Esempio n. 1
0
        public IServiceContainer InitContainer(HttpConfiguration config)
        {
            _diContainer = new ServiceContainer();
            _diContainer.RegisterApiControllers();
            _diContainer.EnableWebApi(config);

            RegisterContainer();
            RegisterFilters();
            RegisterLogger();
            RegisterServices();

            return(_diContainer);
        }
        public static IServiceContainer RegisterDynamicProxy(this IServiceContainer container,
                                                             IAspectConfiguration aspectConfig, Action <IAspectConfiguration> configure = null)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }
            aspectConfig = aspectConfig ?? new AspectConfiguration();

            foreach (var m in _nonAspect)
            {
                aspectConfig.NonAspectPredicates.AddNamespace(m);
            }

            configure?.Invoke(aspectConfig);

            container.AddSingleton <IServiceFactory>(container);
            container.AddSingleton <IServiceContainer>(container);

            container.AddSingleton <IAspectConfiguration>(aspectConfig)
            .AddTransient(typeof(IManyEnumerable <>), typeof(ManyEnumerable <>))
            .AddSingleton <IServiceProvider, LightInjectServiceResolver>()
            .AddSingleton <IServiceResolver, LightInjectServiceResolver>()
            .AddSingleton <IScopeResolverFactory, LightInjectScopeResolverFactory>()
            .AddSingleton <IAspectContextFactory, AspectContextFactory>()
            .AddSingleton <IAspectActivatorFactory, AspectActivatorFactory>()
            .AddSingleton <IProxyGenerator, ProxyGenerator>()
            .AddSingleton <IParameterInterceptorSelector, ParameterInterceptorSelector>()
            .AddSingleton <IPropertyInjectorFactory, PropertyInjectorFactory>()
            .AddSingleton <IInterceptorCollector, InterceptorCollector>()
            .AddSingleton <IInterceptorSelector, ConfigureInterceptorSelector>(nameof(ConfigureInterceptorSelector))
            .AddSingleton <IInterceptorSelector, AttributeInterceptorSelector>(nameof(AttributeInterceptorSelector))    // To register multiple services, you should set a name for each implement type.
            .AddSingleton <IAdditionalInterceptorSelector, AttributeAdditionalInterceptorSelector>()
            .AddSingleton <IAspectValidatorBuilder, AspectValidatorBuilder>()
            .AddSingleton <IAspectBuilderFactory, AspectBuilderFactory>()
            .AddSingleton <IProxyTypeGenerator, ProxyTypeGenerator>()
            .AddSingleton <IAspectCachingProvider, AspectCachingProvider>()
            .AddSingleton <IAspectExceptionWrapper, AspectExceptionWrapper>();

            var aspectValidator = new AspectValidatorBuilder(aspectConfig).Build();

            container.Decorate(aspectValidator.CreateDecorator());

            return(container);
        }
        public static IServiceContainer RegisterDynamicProxy(this IServiceContainer container,
                                                             IAspectConfiguration aspectConfig       = null,
                                                             Action <IAspectConfiguration> configure = null)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }
            aspectConfig = aspectConfig ?? new AspectConfiguration();

            foreach (var m in _nonAspect)
            {
                aspectConfig.NonAspectPredicates.AddNamespace(m);
            }

            configure?.Invoke(aspectConfig);

            container.RegisterInstance <IAspectConfiguration>(aspectConfig)
            .Register(typeof(IManyEnumerable <>), typeof(ManyEnumerable <>))
            .RegisterInstance <IServiceContainer>(container)
            .Register <IServiceProvider, LightInjectServiceResolver>()
            .Register <IServiceResolver, LightInjectServiceResolver>()
            .Register <IAspectContextFactory, AspectContextFactory>()
            .Register <IAspectActivatorFactory, AspectActivatorFactory>()
            .Register <IProxyGenerator, ProxyGenerator>()
            .Register <IParameterInterceptorSelector, ParameterInterceptorSelector>()
            .Register <IPropertyInjectorFactory, PropertyInjectorFactory>()
            .Register <IInterceptorCollector, InterceptorCollector>()
            .Register <IInterceptorSelector, ConfigureInterceptorSelector>()
            .Register <IInterceptorSelector, AttributeInterceptorSelector>()
            .Register <IAdditionalInterceptorSelector, AttributeAdditionalInterceptorSelector>()
            .Register <IAspectValidatorBuilder, AspectValidatorBuilder>()
            .Register <IAspectBuilderFactory, AspectBuilderFactory>()
            .Register <IProxyTypeGenerator, ProxyTypeGenerator>()
            .Register <IAspectCachingProvider, AspectCachingProvider>()
            .Register <IAspectExceptionWrapper, AspectExceptionWrapper>();

            container.Decorate(aspectConfig.CreateDecorator());

            return(container);
        }
 public static IServiceContainer RegisterDynamicProxy(this IServiceContainer containerBuilder, Action <IAspectConfiguration> configure = null)
 {
     RegisterDynamicProxy(containerBuilder, null, configure);
     return(containerBuilder);
 }
Esempio n. 5
0
 public LightInjectServiceResolver(IServiceContainer container)
 {
     _container = container;
 }