开发者

windsor component for is not working as transient

开发者 https://www.devze.com 2023-03-24 09:58 出处:网络
We are using windsorto register a instance for the IUnitOfWorkinterface. UnitOfWorkContainer.Current is a static method which returns an instance of IUnitOfWork.

We are using windsor to register a instance for the IUnitOfWorkinterface. UnitOfWorkContainer.Current is a static method which returns an instance of IUnitOfWork.

 container.Register(Component.For<IUnitOfWork>()
            .Instance(UnitOfWorkContainer开发者_Python百科.Current)
                .LifeStyle.Transient);

The problem is UnitOfWorkContainer.Current is called only ones.


windsor component for is  not working as transient

You are giving Windsor a pre-existing instance. Hence it is not creating it - it's reusing the instance you've given it.

In other words, your code could be rewritten to the equivalent:

var theOneAndOnly = UnitOfWorkContainer.Current;
 container.Register(Component.For<IUnitOfWork>()
            .Instance(theOneAndOnly)
                .LifeStyle.Transient);

I think what you really meant was:

 container.Register(Component.For<IUnitOfWork>()
            .UsingFactoryMethod(() => UnitOfWorkContainer.Current)
                .LifeStyle.Transient);
0

精彩评论

暂无评论...
验证码 换一张
取 消