2

I am creating the service where I am using DI container as an entry point.

My solution is getting heavy what forced me to think how to do unity registration in good way.

I have Service with couple of other dlls with logic. As for now, Unity is installed only in Service where all registration is done.

My service needs to refer all dlls which are needed for DI registration and all nugets installed and used by refereed dlls in DI.

It ends up with pretty heavy packages.config in Service which are needed only for DI registration and it is hard to recognize what is used by service itself and what is not.

I am wondering if there is other way, more cleaner way to do registration without huge list of references in main project and do not brake good practice roles at the same time.

I came up with two solutions: 1 - Create separate dll only for UnityConfiguration, I could have there one public static class like: UnityConfiguration.RegisterComponents() which would be called by Service. In that solution I still will have huge list of reference to all the stuff, but it will be at least separated from main service...

2 - Solutions which probably will not be supported by anyone (by me as well): I would have Unity installed in each dll with logic and each dll could have its own static class UnityConfiguration.RegisterComponents() and main service would call all that registration without knowing the types...

Can you please share your way you would go for ? I am really interested in your opinion...

Wizer
  • 21
  • 1
  • 1
    Although it's a nice question, it could be it tends to have opinionated answers, so it should be a bit more about how you should go at a certain choice vs what we think might be a better strategic decision for you. I for one, like to share only interfaces in a shared class, and these interfaces are then detected and called like `IServiceContainer.Register( IUnityContainer container )` when my app gets loaded, but that's because I load my dlls from a different path, some people like attribute based [MEF](https://docs.microsoft.com/en-us/dotnet/framework/mef/) some 1 single large bootstrap – Icepickle May 14 '19 at 08:17
  • Your question seems related to this one: https://stackoverflow.com/questions/9501604/ioc-di-why-do-i-have-to-reference-all-layers-assemblies-in-entry-application – Steven May 14 '19 at 10:29

0 Answers0