Skip to content

Instantly share code, notes, and snippets.

@ungood
Created March 28, 2012 14:08
Show Gist options
  • Select an option

  • Save ungood/2226469 to your computer and use it in GitHub Desktop.

Select an option

Save ungood/2226469 to your computer and use it in GitHub Desktop.
Simple example of DI
public class OrderProcessor
{
public OrderProcessor(IOrderAllocator allocator, IOrderFulfiller fulfiller)
{
// ...
}
public void Process()
{
}
}
public class Program
{
public static void Main()
{
// this is tedious, especially with large object graphs
processor = new OrderProcessor(
new OrderAllocator(new NHibernateRepository<SalesOrder>(), ...),
new OrderFulfiller(new NHibernateRepository<DistributionOrder>(), ...);
// An IOC does this for you:
processor = container.Resolve<OrderProcessor>();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment