开发者

inject class in to using statement with spring.net

I am developing a .net c# application that开发者_如何学运维 uses dependency injection with spring.net and ran in to an issue. I have the following method:

public string Process()
{    
    using(var p = new MyClass())
    {    
        // do some processing
        return p.RunClass();
    }
}

I am configuring my spring injection to inject in to properties instances of classes etc.

However I am unsure as to how I might inject in to a using statement. I want to replace the above "using(var p = new MyClass())" with the ability to inject in the MyClass and wrap it in a using statement.

Could someone assist me achieving this please?


What about injecting a MyClassFactory? Then you could do something like this:

IMyClassFactory _processorFactory; //inject this
using(var p = _processorFactory.Create())
{
  p.RunClass();
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜