I have 2 services: IDbStorage for database operations and IExceptionManager exception management. ExceptionManager class itself relies on instance of IDbStorage:
public class ExceptionManager : IExceptionManager
{
private IDbStorage _CurrentDbStorage;
public IDbStorage CurrentDbStorage
{
get { return _CurrentDbStorage; }
}
public ExceptionManager(IDbStorage currentDbStorage)
{
_CurrentDbStorage = currentDbStorage;
}
}
In Startup, I declare:
services.AddTransient<IDbStorage, OracleDbStorage>();
services.AddTransient<IExceptionManager, ExceptionManager>();
In all controllers I used both Services. F.e:
public abstract class BusinessObjectManagementController<T1> : ControllerBase where T1 : BusinessObject
{
private IDbStorage _CurrentDbStorage;
public IDbStorage CurrentDbStorage
{
get { return _CurrentDbStorage; }
}
private IExceptionManager _CurrentExceptionMgr;
public IExceptionManager CurrentExceptionMgr
{
get { return _CurrentExceptionMgr; }
}
public BusinessObjectManagementController(IDbStorage currentDbStorage, IExceptionManager currentExceptionMgr)
{
_CurrentDbStorage = currentDbStorage;
_CurrentExceptionMgr = currentExceptionMgr;
}
}
Everything works fine, however I am not sure if the same instance of IDbStorage is injected to CurrentExceptionMgr or new one created?
Thanks.