示例#1
0
        public void Register <I, T>(string name, ObjectLifeSpans lifeSpan)
            where I : class
            where T : class, I
        {
            switch (lifeSpan)
            {
            case ObjectLifeSpans.Thread:
                container.Register <I, T>(name).AsThreadSingleton();
                break;

            case ObjectLifeSpans.WebRequest:
                container.Register <I, T>(name).AsRequestSingleton();
                break;

            case ObjectLifeSpans.Singleton:
                container.Register <I, T>(name).AsContainerSingleton();
                break;

            case ObjectLifeSpans.Session:
                container.Register <I, T>(name).AsSessionSingleton();
                break;

            case ObjectLifeSpans.Cached:
                container.Register <I, T>(name).AsCached();
                break;

            default:
                container.Register <I, T>(name).AsAlwaysNew();
                break;
            }
        }
示例#2
0
        //[DebuggerStepThrough]
        public static void Inject <T>(string name, T existing, ObjectLifeSpans lifeSpan) where T : class
        {
            Check.Argument.IsNotEmpty(name, "name");
            Check.Argument.IsNotNull(existing, "existing");

            resolver.Inject <T>(name, existing, lifeSpan);
        }
示例#3
0
        public void RegisterInstance <T>(string name, T instance, ObjectLifeSpans lifeSpan)
            where T : class
        {
            switch (lifeSpan)
            {
            case ObjectLifeSpans.Thread:
                container.RegisterInstance(name, typeof(T), instance).AsThreadSingleton();
                break;

            case ObjectLifeSpans.WebRequest:
                container.RegisterInstance(name, typeof(T), instance).AsRequestSingleton();
                break;

            case ObjectLifeSpans.Singleton:
                container.RegisterInstance(name, typeof(T), instance).AsContainerSingleton();
                break;

            case ObjectLifeSpans.Session:
                container.RegisterInstance(name, typeof(T), instance).AsSessionSingleton();
                break;

            case ObjectLifeSpans.Cached:
                container.RegisterInstance(name, typeof(T), instance).AsCached();
                break;

            default:
                container.RegisterInstance(name, typeof(T), instance).AsAlwaysNew();
                break;
            }
        }
示例#4
0
        public void Register <I, T>(ObjectLifeSpans lifeSpan)
            where I : class
            where T : class, I
        {
            switch (lifeSpan)
            {
            case ObjectLifeSpans.Singleton:
                container.Register <I, T>(new PerContainerLifetime());
                break;

            case ObjectLifeSpans.WebRequest:
                container.Register <I, T>(new PerRequestLifeTime());
                break;

            case ObjectLifeSpans.Thread:
                container.Register <I, T>(new PerThreadLifetime());
                break;

            case ObjectLifeSpans.Session:
                container.Register <I, T>(new PerSessionLifetime());
                break;

            case ObjectLifeSpans.Cached:
                container.Register <I, T>(new PerCachedLifetime());
                break;

            case ObjectLifeSpans.Transient:
            default:
                container.Register <I, T>();
                break;
            }
        }
示例#5
0
 public void RegisterInstance <T>(string name, T instance, ObjectLifeSpans lifeSpan)
     where T : class
 {
     switch (lifeSpan)
     {
     case ObjectLifeSpans.Singleton:
     case ObjectLifeSpans.Transient:
     case ObjectLifeSpans.WebRequest:
     case ObjectLifeSpans.Thread:
     case ObjectLifeSpans.Session:
     case ObjectLifeSpans.Cached:
     default:
         container.RegisterInstance(typeof(T), instance, name);
         break;
     }
 }
示例#6
0
 public static void RegisterInstance <I, T>(string name, T instance, ObjectLifeSpans lifeSpan)
     where I : class
     where T : class, I
 {
     resolver.RegisterInstance <I, T>(name, instance, lifeSpan);
 }
示例#7
0
 //[DebuggerStepThrough]
 public static void Register <I, T>(ObjectLifeSpans lifeSpan)
     where I : class
     where T : class, I
 {
     resolver.Register <I, T>(lifeSpan);
 }
示例#8
0
 public void Inject <T>(string name, T instance, ObjectLifeSpans lifeSpan) where T : class
 {
     RegisterInstance <T>(name, instance, lifeSpan);
 }