I'm new to autofac and see how to better understand how to pass runtime values ββto a constructor. I read a bunch of stackoverflow questions where this is asked, but none of them are completely complicated. Should we use delegates, factory to create a service, etc. I know that passing a container around is not the best way to accomplish this.
In my particular case, I have a service that accesses several dependencies, say, logging, a datosensor, etc. Along with several transferred services, I also have runtime parameters that I need to do, for example, userid, password. A user ID and password are required for SomeService and are viewed when the web viewer performs a specific action. Below is what I have and highlighted.
public class SomeService : ISomeService
{
private readonly IDataProvider _dataProvider;
private readonly ILog _log;
private readonly string _username;
private readonly string _password;
public SomeService(IDataProvider dataProvider, ILog log,
string username, string password)
{
_dataProvider = dataProvider;
_log = log;
_username = username;
_password = password;
}
}
Date provider and log configured in autofac
builder.RegisterType<DataProviderService>().As<IDataProvider>()
builder.RegisterType<SomeLogService>().As<ILog>()
"SomeService" , , , , autofac. Autofac - , , , , , .