Ejemplo n.º 1
0
        public I GetService <I>()
            where I : class
        {
            Type key = typeof(I);

            if (!mContainer.ContainsKey(key))
            {
                return(default(I));
            }

            ServiceHolder <I> container = (ServiceHolder <I>)mContainer[key];

            return(container.Service);
        }
Ejemplo n.º 2
0
        private bool RegisterServiceInternal <I>(I instance, Lazy <I> lazyInstance, string serviceName = null)
            where I : class
        {
            if (instance == default(I) && lazyInstance == null)
            {
                throw new ArgumentNullException("RegisterService - Cannot be null");
            }

            Type key = typeof(I);

            if (mContainer.ContainsKey(key))
            {
                return(false);
            }

            var container = new ServiceHolder <I>(instance, lazyInstance, serviceName);

            mContainer.AddOrUpdate(key, container, (k, o) => container);

            return(true);
        }