I have some code that looks something like this:
public MyService(IDependency dependency)
{
_dependency = dependency;
}
public Message Method1()
{
_dependency.DoSomething();
}
public Message Method2()
{
_dependency.DoSomething();
}
public Message Method2()
{
_dependency.DoSomething();
}
Now I have just realised that because the dependency object contains internal state information. I need to new up a new instance of it in each method call
So what is the best way to do this and still not have a concrete instance newed up ?
Would you use an IoC container and make a call to to the container in each and every one of the methods? Or is there a slicker way where you can only make one call to the container?
What if I wasn't using an IoC container - would there be a way to not new up a concrete instance in each method?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…