So I'm in the process of upgrading various modules to Sitecore 8.2. Among other things this involves getting rid of IoC container project references and getting on board with the Sitecore one.
And herein lies my question.
It seems to me that if I just add a reference to Microsoft.Extensions.DependencyInjection
I am really just replacing one DI reference with another one. Also; what if the main project that my module will plug into, has that container replaced - like with SimpleInjector or Unity or such?
Reading through Kam's post on DI in 8.2 it seems to me that the best approach for a module would be to use Direct Registration
. Like so:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<services>
<register
serviceType="Type.IName, Assembly"
implementationType="Type.Name, Assembly"
lifetime="Transient" />
</services>
</sitecore>
</configuration>
Doing it like this is agnostic towards the actual container in use; saves me a project reference to any container. Seems like a win/win. But is it?
When Sitecore gets reconfigured to use another container; will that container also be used to resolve these
<register />
entries? (as opposed to what Kam suggests; resolve these via Reflection)Am I really not saving anything because Sitecore already references
Microsoft.Extensions.DependencyInjection
and one more reference from a module will make no difference at all?