I have a console app A and a web app B where A needs to use a service class in B. To deal with dependencies I tried to make an autofac module in B that is registered in A's Main method:
public class ImageServiceModule : Module
{
protected override void Load(ContainerBuilder builder)
{
builder.RegisterType<ImageService>().As<IImageService>();
...
var configurationBuilder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json");
var configuration = configurationBuilder.Build();
var services = new ServiceCollection();
services.Configure<StorageSettings>(configuration.GetSection("StorageSettings"));
builder.Populate(services);
}
}
Now, the problem is that since the program is run in the context of A, B reads appSettings from A...
Is there a way to make the services registered in the module read from B's appsettings instead? Or is autofac modules a wrong approach to use here in the first place?