Skip to content

Instantly share code, notes, and snippets.

@cellfish

cellfish/good_ioc.cs

Last active Aug 29, 2015
Embed
What would you like to do?
Example of good IoC container usage.
class SomeChildObject : IChildObject
{
public SomeChildObject(IMyLowLevelDependency foo)
{
foo.DoSomething();
}
}
class MyObject
{
private ISomeDependency dependency;
private IChildFactory childFactory;
private IContainer container;
public MyObject(ISomeDependency dependency, IChildFactory childFactory, IContainer container)
{
this.dependency = dependency;
this.childFactory = childFactory;
this.container = container;
}
public IChildObject DoStuff()
{
return this.childFactory.Create(this.container.Resolve<IMyLowLevelDependency>());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.