Reputation: 5918
I have interface a question/confusion related to IoC purposes. Consider the following:
ISite - interface
ImapSite: ISite - non default constructor.
I register the interface with concrete imp using the container as following:
_container.RegisterType<ISite, ImapSite>(new InjectionConstructor(typeof(string), typeof(Account)));
And resolve it using:
_site = _container.Resolve<ISite>(new DependencyOverride[]
{
new DependencyOverride<string>(host),
new DependencyOverride<Account>(Account.FromAppConfig())
});
I am now wondering if the this kinda beats the purpose of IoC because if I can't constrain what kind of constructor an ISite implementation will have, when ImapSite changes ctor signature I still have to change it everywhere in code.
Upvotes: 0
Views: 963
Reputation: 156524
Yes, if you are passing constructor arguments directly that defeats the purpose of IoC. You should rethink the design of your classes so that only services are injected. Maybe the arguments you're passing in should actually be arguments to individual methods on the class?
Upvotes: 2