I created several Autofac modules ... Now I want to register some of them in my container using web.config ... In my web.config I wrote:
<autofac defaultAssembly="Autofac.Example"> <modules> <module type="DebugModuleTest1"></module> <module type="DebugModuleTest2"></module> </modules> </autofac>
Now I need to create a container. But the autofile documentation is not clear to me. I do not understand what I need to do to read my modules and create a container.
public class MyCustomContainer { public void Build(HttpConfiguration config) { var builder = new ContainerBuilder(); Microsoft.Extensions.Configuration.ConfigurationBuilder x = new Microsoft.Extensions.Configuration.ConfigurationBuilder();
I am using the latest version of Autofac, so I do not have the ConfigurationSettingsReader class.
Can anybody help me?
EDIT
I found an interesting save configuration on web.config, because this way I could “modify” web.config to fit my solution configuration (you know, classic web.debug.config, web.release.config, etc. ) ....
This could help register the correct modules, avoiding the use of directives (#if bla bla bla, ...) or just conditions ...
I already use modules, but I don’t think that the right solution adds a property inside the module to select the component for resolution according to the selected environment where I want to deploy the project. I just think of this solution reading this example (By the way, Flexibility to Override still applies to ConfigurationSettingsReader . Is this normal?)
autofac
Ciccio
source share