Hi Everyone,
I have a small issue but cannot figure out to get it working.
I have a windows Service and each minute it does some tasks.
To test if I can store all my exceptions in memory (and later send them to a database as soon as a disconnect db is connected again).
In the class holding the List<encouteredexceptions> is see the exception is added.
In the service1.cs file I have:
private IUnityContainer _container;
private MainService _service;
public srvBackground()
{
InitializeComponent();
_container = new UnityContainer();
_container.RegisterType<IExceptions, Exceptions>("EncounteredExceptions", new ContainerControlledLifetimeManager());
_service = new MainService();
}
In my LogData class I have:
_exceptions = _container.Resolve<Exceptions>("EncounteredExceptions");
The Exceptions class holds:
private EncounteredException _encounteredException;
private List<EncounteredException> _exceptionsList = new List<EncounteredException>();
public List<EncounteredException> ExceptionsList
{
get { return _exceptionsList ?? (_exceptionsList = new List<EncounteredException>()); }
}
public Exceptions()
{
}
public void Add(Exception exception)
{
try
{
_encounteredException = new EncounteredException();
_encounteredException.exception = exception;
_encounteredException.exceptionProcessedToDatabase = false;
_encounteredException.excptionOccurred = DateTime.Now;
_exceptionsList.Add(_encounteredException);
}
catch (Exception err)
{
}
}
How I have to Update the unity Container so that a Resolve in another class would give me the EncounteredExceptions list?