コード例 #1
0
        public static void Populate(this IIocRegistrar registrar,
                                    IEnumerable <ServiceDescriptor> descriptors)
        {
            Ensure.NotNull(registrar, nameof(registrar));

            if (descriptors != null)
            {
                foreach (var descriptor in descriptors)
                {
                    var lifetime = GetLifetimeType(descriptor.Lifetime);
                    if (descriptor.ImplementationType != null)
                    {
                        registrar.RegisterType(descriptor.ServiceType, descriptor.ImplementationType, lifetime);
                    }
                    else if (descriptor.ImplementationFactory != null)
                    {
                        registrar.RegisterDelegate(descriptor.ServiceType, r => descriptor.ImplementationFactory(r.GetService <IServiceProvider>()), lifetime);
                    }
                    else
                    {
                        registrar.RegisterInstance(descriptor.ServiceType, descriptor.ImplementationInstance);
                    }
                }
            }
        }
コード例 #2
0
ファイル: ConfigurationExtensions.cs プロジェクト: d18zj/qim
        public static IIocAppConfiguration CreateIocAppConfiguration(this IAppConfiguration configuration,
                                                                     IIocRegistrar registrar, IIocResolver resolver)
        {
            Ensure.NotNull(configuration, nameof(configuration));
            var appConfiguration = configuration as AppConfiguration;

            if (appConfiguration == null)
            {
                throw new InvalidOperationException($"The method only support for AppConfiguration.");
            }
            RegisterCommonComponents(registrar);
            var result = new IocAppConfiguration(appConfiguration.ConfigDictionary, registrar, resolver);

            registrar.RegisterInstance <IIocAppConfiguration>(result);
            registrar.RegisterInstance <IAppConfiguration>(result);
            return(result);
        }