I’ve been learning IoC, Dependency Injection etc. and enjoying the process. The benefits of decoupling and programming to interfaces are, to me, a no-brainer.
However, I really don’t like binding myself to a specific framework like Unity or Autofac or Windsor – because I’m still learning and haven’t yet decided which is best for my purposes.
So, how can I wrap around something like Unity so I could easily swap in Windsor at a later date? (or whatever). And don’t you dare say use another one to inject the first one 😉
Thanks!
R.
P.s. I tagged Unity as that’s my current personal preference (I just lurve Entlib).
You can certainly try making an abstraction from the container by declaring an
IContainerwith sayResolveandRegister. I did that a couple of times. Then you would go ahead and implement a Container : IContainer and encapsulate an actual IoC container with your abstraction. I tried that with Unity and Castle Windsor.But hey, soon I realised that this was really an over-engineering. I then understood that I tried to abstract from abstraction, yet to build another abstraction. This could be fine to learn the concept, but it was a real pain in the neck in a real project. I would highly recommend against an abstraction from IoC container. If you correctly use DI principle it will be fairly easy to change your container anyways.
The code looks overcomplicated, like
See this post by Ayende.