When using autofac json configuration to register modules you can pass in properties and/or parameters.
{
"modules": [
{
"type": "MyProject.Core.MyModule, MyProject.Core",
"properties": {
"ModuleProperties": {
"prop1": "value1",
"prop2": "value2"
}
}
]
}
public class MyModule : Autofac.Module
{
public Dictionary<string, string> ModuleProps { get; set; }
protected override void Load(ContainerBuilder builder)
{
builder.RegisterType<MyType>.As<IMyInterface>();
}
}
Is there a way to pass ModuleProps to the type I just registered?
So I figured it out. My concert type
MyTypehas a constructor with aDictionary<string, string> configparameter and when I register the type I can pass it in likebuilder.RegisterType<MyType>.As<IMyInterface>.WithParameter("config", Config).