I have a code snippet that creates an instance based on the configuration specified in the JSON file (I am thinking about LoginLogic)
public ILoginModule GetLoginModule()
{
if (loginModule == null)
{
loginModule = new LoginModule.LoginModule(_configuration);
Type loginLogicType = CreateTypeFromConfiguration("LoginModule", "LoginLogic", "MyProject.Modules.LoginModule.Logic.LoginLogic");
loginModule.SetLoginLogic((ILoginLogic)Activator.CreateInstance(loginLogicType));
}
return loginModule;
}
Here's what the LoginLogic class looks like
public class LoginLogic : ILoginLogic
{
private IConfiguration _configuration;
protected ILoginRepository loginRepository;
public LoginLogic()
{
}
public LoginLogic(IConfiguration configuration)
{
_configuration = configuration;
loginRepository = new LoginRepository(_configuration);
}
}
Activator uses an empty constructor to create an object
I need to have the data that I call in the next constructor
loginRepository I can move because it does not change anything
What to do with configuration? It is injected automatically by Net. Core
Configure<TOptions>. Why not use what's already built in?