I'm learning AutoFac. I like the idea of modules. From my understanding, I could for example create a module that registers some part of my application dependencies to the container to create some abstraction above it. However, I don't really know what to do in situations where I have multiple modules.
First thing is, should I create a seperate LoggerModule just to do this:
builder.RegisterType<'MyLogger>().As<'ILogger>();
Or should it be put drectly in composition root? The question comes from my confusion if it's a good idea to register modules (higher abstraction) and services (lower abstraction) on the same level of composition root. Should modules be created only for services that use many dependencies, to make the registration simpler on the composition root level?
Another thing: What about my other modules that register services that require ILogger? Should I just assume that ILogger is already registered and just c.Resolve<'ILogger>() or should I register it again so that every module has all needed dependencies registered?
Can I create a module that registers other modules?
I tried to look for answers to these, but I found only topics that were close, but not really about my issue.
Think of modules as vehicles for configuration, not as components of your application. They exist to setup the container with the components your application will depend upon. With this in mind: