コード例 #1
0
        public IoC.IContainer RegisterInstance <TInterface>(TInterface instance, IoC.Lifetime lifetime = IoC.Lifetime.Singleton)
            where TInterface : class
        {
            var builder = new ContainerBuilder();

            builder.RegisterInstance(instance)
            .InstanceLifetime(lifetime);
            builder.Update(_container.ComponentRegistry);
            return(this);
        }
コード例 #2
0
        public IoC.IContainer RegisterInstance(Type t, string name, object instance, IoC.Lifetime lifetime = IoC.Lifetime.Singleton)
        {
            var builder = new ContainerBuilder();

            builder.RegisterInstance(instance)
            .Named(name, t)
            .InstanceLifetime(lifetime);
            builder.Update(_container.ComponentRegistry);
            return(this);
        }
コード例 #3
0
        public IoC.IContainer RegisterType <TFrom, TTo>(IoC.Lifetime lifetime, params IoC.Injection[] injections) where TTo : TFrom
        {
            var injectionMembers = GetInjectionParameters(injections);
            var builder          = new ContainerBuilder();

            if (typeof(TTo).IsGenericType)
            {
                builder.RegisterGeneric(typeof(TTo))
                .As(typeof(TFrom))
                .InstanceLifetime(lifetime)
                .WithParameters(injectionMembers);
            }
            else
            {
                builder.RegisterType(typeof(TTo))
                .As(typeof(TFrom))
                .InstanceLifetime(lifetime)
                .WithParameters(injectionMembers);
            }
            builder.Update(_container.ComponentRegistry);
            return(this);
        }
コード例 #4
0
        public IoC.IContainer RegisterType(Type from, Type to, string name, IoC.Lifetime lifetime, params IoC.Injection[] injections)
        {
            var injectionMembers = GetInjectionParameters(injections);
            var builder          = new ContainerBuilder();

            if (to.IsGenericType)
            {
                builder.RegisterGeneric(to)
                .Named(name, from)
                .InstanceLifetime(lifetime)
                .WithParameters(injectionMembers);
            }
            else
            {
                builder.RegisterType(to)
                .Named(name, from)
                .InstanceLifetime(lifetime)
                .WithParameters(injectionMembers);
            }
            builder.Update(_container.ComponentRegistry);
            return(this);
        }