Ejemplo n.º 1
0
 public bool RegisterServiceType <T, C>(T service, C childService, bool overwriteIfExists = false)
 {
     if (!ServicesTypes.ContainsKey(typeof(T)))
     {
         if (typeof(T).IsInstanceOfType(typeof(C)))
         {
             ServicesTypes.Add(typeof(T), typeof(C));
             return(true);
         }
         throw new TypeAccessException("Service lazy load type exception");
     }
     else
     {
         if (overwriteIfExists)
         {
             if (typeof(T).IsInstanceOfType(typeof(C)))
             {
                 ServicesTypes.Add(typeof(T), typeof(C));
                 return(true);
             }
             throw new TypeAccessException("Service lazy load type exception");
         }
     }
     return(false);
 }
 public GenericService GetService(ServicesTypes type)
 {
     if (_services.Exists(x => x.Type == type))
     {
         return(_services.Find(x => x.Type == type));
     }
     else
     {
         Debug.LogWarning("Controller not founded '" + type + "' returning null");
         return(null);
     }
 }
Ejemplo n.º 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");
                }
            }
        }