Skip to content

Instantly share code, notes, and snippets.

@cellfish
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cellfish/651b486ac14ad39e4365 to your computer and use it in GitHub Desktop.
Save cellfish/651b486ac14ad39e4365 to your computer and use it in GitHub Desktop.
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