Click here to Skip to main content
15,881,455 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:
C#
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:
C#
_exceptions = _container.Resolve<Exceptions>("EncounteredExceptions");

The Exceptions class holds:
C#
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)
            {
                // ToDO
            }
        }

How I have to Update the unity Container so that a Resolve in another class would give me the EncounteredExceptions list?
Posted
Updated 1-Apr-15 4:31am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900