Exemple #1
0
 public T GetService <T>()
 {
     if (InitialisedServices.ContainsKey(typeof(T)))
     {
         return((T)InitialisedServices[typeof(T)]);
     }
     throw new KeyNotFoundException();
 }
Exemple #2
0
 public bool RegisterServiceObject <T>(T service, bool overwriteIfExists = false)
 {
     lock (InitialisedServices)
     {
         if (!InitialisedServices.ContainsKey(typeof(T)))
         {
             InitialisedServices.Add(typeof(T), service);
             return(true);
         }
         else if (overwriteIfExists)
         {
             InitialisedServices[typeof(T)] = service;
             return(true);
         }
         return(false);
     }
 }
Exemple #3
0
        public T GetServiceLazyLoading <T>()
        {
            if (this.ServicesTypes.ContainsKey(typeof(T)))
            {
                return((T)ServicesTypes.Where(x => x.Key == typeof(T)).FirstOrDefault().Value);
            }
            else
            {
                try
                {
                    ConstructorInfo constructor = ServicesTypes[typeof(T)].GetType().GetConstructor(new Type[0]);
                    Debug.Assert(constructor != null, "İlgili nesne için uygun yapılandırıcı metod bulunamamıştır " + typeof(T));

                    T service = (T)constructor.Invoke(null);
                    InitialisedServices.Add(typeof(T), service);
                    return(service);
                } catch (KeyNotFoundException)
                {
                    throw new ApplicationException("İlgili servis kaydı bulunamamıştır");
                }
            }
        }