Testing Castle windsor Component with PerWebRequest lifestyle

后端 未结 4 2021
夕颜
夕颜 2020-12-31 02:00

I\'m trying to do some testing with castle windsor involved, in one of my tests I want to check the windsor installers, so I check that the container can resolve my componen

4条回答
  •  情歌与酒
    2020-12-31 02:51

    From version 5 of Windsor the accepted answer doesn't work if you are using Castle.Facilities.AspNet.SystemWeb.WebRequestScopeAccessor because the PerWebRequest lifestyle is already a scoped lifestyle.

    I got it to work by changing the the ComponentModelCreated delegate to the following:

    void Kernel_ComponentModelCreated(Castle.Core.ComponentModel model)
    {
        const string CastleScopeAccessorType = "castle.scope-accessor-type";
    
        if (model.ExtendedProperties.Contains(CastleScopeAccessorType))
        {
            model.ExtendedProperties.Remove(CastleScopeAccessorType);
        }
    }
    

提交回复
热议问题