开发者

windsor component for is not working as transient

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜