コード例 #1
0
        /// <summary>
        /// Register components using assembly from parameter
        /// </summary>
        /// <param name="container">ioc container</param>
        /// <param name="types">assemblies</param>
        public static void Regist(this Container container, IEnumerable <Type> types)
        {
            var service = new RegistService(new ResolveLoader(container));

            container.ResolveUnregisteredType += (sender, e) =>
            {
                var unregistered = e.UnregisteredServiceType;

                if (!unregistered.IsClass || !unregistered.GetConstructors().Any(info => info.IsPublic))
                {
                    return;
                }

                var component = unregistered.GetCustomAttribute <ComponentAttribute>(true);

                var lifestyle = component == null
                    ? Lifestyle.Singleton
                    : LifeStyleFactory.Create(component.LifestyleType);

                var registration = lifestyle.CreateRegistration(unregistered, container);

                e.Register(registration);
            };

            service.Register(types);
        }
コード例 #2
0
 public void Resolve(Type interfaceType, Type implemented, LifestyleType lifestyleType)
 {
     Container.Register(interfaceType, implemented, LifeStyleFactory.Create(lifestyleType));
 }