Created
March 28, 2012 14:08
-
-
Save ungood/2226469 to your computer and use it in GitHub Desktop.
Simple example of DI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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