コード例 #1
0
        public void LoadFromXml(XElement xeConfig)
        {
            DiManager.GetInstance().Dispose();
            foreach (XElement xeRegistration in xeConfig.Elements("Registration"))
            {
                string sInterface = xeRegistration.Attribute("Interface").Value;
                string sClass     = xeRegistration.Attribute("Class").Value;
                string sLifetime  = xeRegistration.Attribute("Lifetime")?.Value;

                Lifetime targetLifetime = Lifetime.NewInstanceEveryTime;
                if (sLifetime != null)
                {
                    if (sLifetime == "Singleton")
                    {
                        targetLifetime = Lifetime.Singleton;
                    }
                }

                Type targetInterface = Type.GetType(sInterface);
                if (targetInterface == null)
                {
                    throw new ArgumentException(string.Format("Could not get a Type from: {0}", sInterface));
                }
                Type targetClass = Type.GetType(sClass);
                if (targetClass == null)
                {
                    throw new ArgumentException(string.Format("Could not get a Type from: {0}", sClass));
                }

                DiManager.GetInstance().registerType(targetInterface, targetClass, targetLifetime);
            }
        }
コード例 #2
0
 protected override void dispose()
 {
     this.builder = null;
     this.container?.Dispose();
     this.container = null;
     this.registeredTypes.Clear();
     this.registeredTypes = null;
     this.typeTranslations.Clear();
     this.typeTranslations = null;
     DiManager.instance    = null;
 }
コード例 #3
0
 /// <summary>
 /// get the current instance
 /// </summary>
 /// <returns>the. instance.</returns>
 public static DiManager GetInstance()
 {
     // Support multithreaded applications through
     // 'Double checked locking' pattern which (once
     // the instance exists) avoids locking each
     // time the method is invoked
     if (DiManager.instance == null)  // if instance is not null, use existing one
     {
         lock (DiManager.lockSync)
         {
             if (DiManager.instance == null)
             {
                 DiManager.instance = new DiManager();
             }
         }
     }
     return(DiManager.instance);
 }