Created
September 3, 2012 18:40
-
-
Save davybrion/3612032 to your computer and use it in GitHub Desktop.
code snippets for "Introduction To IOC With Castle Windsor" post, part I
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
| private readonly IOrderDataAccessor _accessor; | |
| public OrderRepository(IOrderDataAccessor accessor) | |
| { | |
| _accessor = accessor; | |
| } |
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
| IOrderRepository repository = Container.Resolve<IOrderRepository>(); |
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
| OrderRepository repo = new OrderRepository(new OrderDataAccessor()); |
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
| OrderRepository repository = Container.Resolve<OrderRepository>(); |
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 static class Container | |
| { | |
| private static readonly IWindsorContainer _container; | |
| static Container() | |
| { | |
| _container = new WindsorContainer(); | |
| _container.AddComponent<IOrderDataAccessor, OrderDataAccessor>(); | |
| _container.AddComponent<OrderRepository>(); | |
| } | |
| public static T Resolve<T>() | |
| { | |
| return _container.Resolve<T>(); | |
| } | |
| } |
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
| _container.AddComponent<IOrderDataAccessor, OrderDataAccessor>(); |
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
| _container.AddComponent<OrderRepository>(); |
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 interface IOrderRepository | |
| { | |
| Order GetById(Guid id); | |
| IEnumerable<Order> GetAll(); | |
| Order FindOne(Criteria criteria); | |
| IEnumerable<Order> FindMany(Criteria criteria); | |
| void Store(Order order); | |
| } |
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 OrderRepository : IOrderRepository |
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
| static Container() | |
| { | |
| _container = new WindsorContainer(); | |
| _container.AddComponent<IOrderDataAccessor, OrderDataAccessor>(); | |
| _container.AddComponent<IOrderRepository, OrderRepository>(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment