I am trying to decide if it makes sense to go through an extra effort to encapsulate my IoC container. Experience tells me that I should lay a layer of encapsulation between my applications and any third-party component. I just don't know if this borders on excess.
I can think of situations where I can switch containers. For example, my current container is no longer supported, or another container is proven to be lighter / more efficient and better suited to my needs. If this happens, I will potentially have a lot of reconnection.
To be clear, I consider encapsulation of registration and type resolution. I believe that this does not require permission encapsulation - I would hope that in normal practice there is delegation of the helper / utility class to the container.
EDIT:
It is suggested that I prefer to plug in my types programmatically for type safety, compile-time checking, and refactoring. This is this code and its dependence on the container from which I want to protect myself.
I also used the IoC container for several other projects that share a lot of the same relationship, but the container is a pain to work with, so I want to change. But the change means that I am losing the possibility of reusing the registration code. Therefore, why am I considering encapsulation. This is not a huge burden, but the fact that I, nevertheless, would like to mitigate.
I'm looking for:
- Minimize the impact of changes in containers / container versions.
- Provide some level of consistency in registering types in projects that can use different containers.
- Provide interface methods that make sense to me (RegisterSingleton <T, T>, not RegisterType <T, T> (SomeLifetimeProvider) - using Unity as an example).
- Enlarge the container when conditions / scalability change, e.g. adding better caching, logging, etc. at the time of authorization / registration.
- Provide my own model for registering type mappings.
- Suppose I want to create a bunch of RegistrationHandler objects in an assembly / package, and so I can easily separate the registration responsibilities from several classes and automatically intercept these handlers without changing the code elsewhere.
I understand that this is a bit subjective, so the pros / cons can be useful
Thanks!
encapsulation ioc-container
Ryan emerle
source share