开发者

inject class in to using statement with spring.net

开发者 https://www.devze.com 2023-04-10 11:29 出处:网络
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:

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

精彩评论

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

关注公众号