Esempio n. 1
0
        protected override void Load(IRegistrator builder, ITypeFinder typeFinder, SiteConfig config)
        {
            foreach (var type in typeFinder.FindClassesOfType <ISettings>())
            {
                builder.RegisterDelegate(type, (c) =>
                {
                    ISettingService serviceCtx = c.Resolve <ISettingService>();
                    var method = serviceCtx.GetType().GetMethod("LoadSetting").MakeGenericMethod(type);
                    return(method.Invoke(serviceCtx, null));
                }, Reuse.InWebRequest);
            }

            builder.Register <IPageHeadBuilder, PageHeadBuilder>(Reuse.InWebRequest);

            builder.RegisterDelegate <HttpContextBase>(c => {
                return(HttpContext.Current != null ? (new HttpContextWrapper(HttpContext.Current) as HttpContextBase) : (new FakeHttpContext("~/") as HttpContextBase));
            }, Reuse.InResolutionScope);

            builder.RegisterDelegate <HttpRequestBase>(c => c.Resolve <HttpContextBase>().Request, Reuse.InResolutionScope);

            builder.RegisterDelegate <HttpResponseBase>(c => c.Resolve <HttpContextBase>().Response, Reuse.InResolutionScope);

            builder.RegisterDelegate <HttpServerUtilityBase>(c => c.Resolve <HttpContextBase>().Server, Reuse.InResolutionScope);

            builder.RegisterDelegate <HttpSessionStateBase>(c => c.Resolve <HttpContextBase>().Session, Reuse.InResolutionScope);

            builder.Register <IWebHelper, WebHelper>(Reuse.Singleton);
            builder.Register <ICacheManager, MemoryCacheManager>(Reuse.Singleton);
            builder.Register <IRouteRegistrator, RouteRegistrator>(Reuse.Singleton);
            builder.Register <IPluginFinder, PluginFinder>(Reuse.Singleton);
        }
Esempio n. 2
0
    public static void ScanAssemblies <T>(this IRegistrator registrator,
                                          IReuse reuse = null,
                                          Made made    = null,
                                          Setup setup  = null,
                                          IfAlreadyRegistered ifAlreadyRegistered = IfAlreadyRegistered.AppendNotKeyed)
    {
        var serviceTypeOf = typeof(T);
        var scannedTypes  = AssemblyFinder.ScanAssemblies()
                            .Where(assembly =>
        {
            try
            {
                return(assembly.DefinedTypes != null);
            }
            catch
            {
                return(false);
            }
        })
                            .SelectMany(assembly => assembly.DefinedTypes)
                            .Where(type => !type.IsAbstract && serviceTypeOf.GetTypeInfo()
                                   .IsAssignableFrom(type));

        foreach (var eachScannedType in scannedTypes)
        {
            registrator.Register(eachScannedType.AsType(), reuse, made, setup, ifAlreadyRegistered);

            var interfaces = eachScannedType.ImplementedInterfaces;
            foreach (var eachInterface in interfaces)
            {
                registrator.Register(eachInterface, eachScannedType.AsType(), reuse, made, setup, ifAlreadyRegistered);
            }
        }
    }
Esempio n. 3
0
            private static void RegisterRepositories(IRegistrator container, bool singletonDecorators)
            {
                var ns = typeof(EntityVersionRepository).Namespace;

                container.RegisterMany(
                    typeof(EntityVersionRepository).GetAssembly().GetLoadedTypes().Where(i =>
                {
                    return(i.Namespace == ns && !i.IsInterface && !i.IsAbstract &&
                           (i.Name.EndsWith("Service") || i.Name.EndsWith("Repository")) &&
                           i.Name != "UniqueUserRepository" &&
                           i.Name != "UniqueUserConnUpdateHandlerRepository" &&
                           i.Name != "UniqueUserUuidHandlerRepository");
                }), Reuse.Singleton, serviceTypeCondition: s => s.IsInterface && s.Namespace == ns,
                    ifAlreadyRegistered: IfAlreadyRegistered.Throw
                    );

                container
                .Register <IUniqueUserToConnChangeNotifier,
                           UniqueUserToConnChangeNotifier>(Reuse.Singleton);

                container.Register <IUniqueUserRepository, UniqueUserRepository>(
                    Reuse.Singleton);
                container.Register <IUniqueUserRepository, UniqueUserConnUpdateHandlerRepository>(
                    setup: Setup.Decorator, reuse: singletonDecorators ? Reuse.Singleton : null);
                container.Register <IUniqueUserRepository, UniqueUserUuidHandlerRepository>(
                    setup: Setup.Decorator, reuse: singletonDecorators ? Reuse.Singleton : null);
                container.Register <IUniqueUserRepository, UniqueUserToUserReplicator>(
                    setup: Setup.Decorator, reuse: singletonDecorators ? Reuse.Singleton : null);
            }
Esempio n. 4
0
        /// <summary>
        /// Ensures that a service always resolves as lazy proxy (uses DefaultProxyBuilder).
        /// </summary>
        /// <param name="registrator">The registrator.</param>
        /// <param name="interfaceType">The type of the interface.</param>
        /// <param name="serviceKey">Optional service key.</param>
        public static IRegistrator ResolveAsLazyViaProxyBuilder(this IRegistrator registrator, Type interfaceType, object serviceKey = null)
        {
            // registration of lazy interceptor
            registrator.Register(typeof(LazyInterceptor <>), setup: Setup.Wrapper, ifAlreadyRegistered: IfAlreadyRegistered.Keep);

            // lazy proxy wrapper
            var proxyBuilder = new DefaultProxyBuilder();
            var proxyType    = proxyBuilder.CreateInterfaceProxyTypeWithTargetInterface(interfaceType,
                                                                                        ArrayTools.Empty <Type>(), ProxyGenerationOptions.Default);

            // decorator for the generated proxy class
            var decoratorSetup = GetDecoratorSetup(serviceKey);

            // make typeof(LazyInterceptor<interfaceType>[])
            var lazyInterceptorArrayType = typeof(LazyInterceptor <>).MakeGenericType(interfaceType).MakeArrayType();

            // register the proxy class as decorator
            registrator.Register(interfaceType, proxyType,
                                 Reuse.Transient,
                                 setup: decoratorSetup,
                                 made: Made.Of(type => type.PublicConstructors().SingleOrDefault(ctor => ctor.GetParameters().Length != 0),
                                               Parameters.Of
                                               .Type(typeof(IInterceptor[]), lazyInterceptorArrayType)
                                               .Type(interfaceType, r => null)));

            return(registrator);
        }
Esempio n. 5
0
            private static void RegisterRestObjects(IRegistrator container)
            {
                var apiAssembly = typeof(BearerAuthenticationController).Assembly;
                var ns          = typeof(BearerAuthenticationController).Namespace;

                var restAssemblyTypes = apiAssembly.GetLoadedTypes().Where(i =>
                {
                    return(i.Namespace == ns && !i.IsInterface && !i.IsAbstract && (i.Name.EndsWith("Service") ||
                                                                                    (i.Name.EndsWith("Converter") &&
                                                                                     i.Name !=
                                                                                     "SharedDashboardModelConverter" &&
                                                                                     i.Name !=
                                                                                     "TemporaryProjectTravelsModelConverter" &&
                                                                                     i.Name !=
                                                                                     "ProjectWorkHourPriceModelConverter"
                                                                                    )
                                                                                    ));
                }
                                                                           );

                container.RegisterMany(restAssemblyTypes, Reuse.Scoped, serviceTypeCondition: s => s.IsInterface && s.Namespace == ns, ifAlreadyRegistered: IfAlreadyRegistered.Throw);
                container.Register <IRestSettingsService, RestSettingsService>(Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Replace);
                container.Register <IModelConverter <WorkPriceEx>, WorkHourPriceModelConverter>(Reuse.Scoped, ifAlreadyRegistered: IfAlreadyRegistered.Replace);
                container.Register <IModelConverter <TemporaryProjectTravelExpenseModel>, TemporaryProjectTravelsModelConverter>(Reuse.Scoped, ifAlreadyRegistered: IfAlreadyRegistered.Replace);
                container.Register <PsaReportFactory, PsaReportFactory>(Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Throw);
                container.RegisterDelegate <ReportControllerFactory <IPsaContext> >(c => PsaReportFactory.Factory, Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Throw);
                container.RegisterDelegate <IReportFactoryService <IPsaContext> >(c => PsaReportFactory.Factory, Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Throw);
                container.RegisterDelegate <IPsaReportFactoryService>(c => PsaReportFactory.Factory, Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Throw);
                container.Register <IWhiteListService, WhiteListService>(Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Replace);
            }
Esempio n. 6
0
        private static void BuildMediator(IRegistrator container, TextWriter writer)
        {
            container.RegisterInstance(writer);
            container.RegisterMany(new[] { typeof(Program).GetAssembly() }, Registrator.Interfaces);

            container.Register(typeof(IMessageHandler <,>), typeof(MiddlewareMessageHandler <,>), setup: Setup.Decorator);
            container.Register(typeof(BroadcastMessageHandler <>));
        }
Esempio n. 7
0
        public CompositionRoot(IRegistrator container)
        {
            container.Register <IDatastoreDbFactory, DatastoreDbFactory>(Reuse.Singleton);
            container.Register(reuse: Reuse.Singleton, made: Made.Of(r => ServiceInfo.Of <IDatastoreDbFactory>(), f => f.CreateDatastoreDb()));

            container.RegisterDelegate <ServiceFactory>(r => r.Resolve);
            container.RegisterMany(new[] { typeof(IMediator).GetAssembly(), typeof(DatastoreDbFactory).GetAssembly() }, Registrator.Interfaces);
        }
Esempio n. 8
0
 public void RegisterTypes(IRegistrator registrator)
 {
     // ConfigProvider
     registrator.Register(typeof(IJsonConfigAssembliesProvider <>), typeof(JsonConfigAssembliesProvider <>), Reuse.Singleton);
     registrator.Register(typeof(IJsonConfigNamespacesProvider <>), typeof(JsonConfigNamespacesProvider <>), Reuse.Singleton);
     registrator.Register(typeof(IJsonConfigNamesProvider <>), typeof(JsonConfigNamesProvider <>), Reuse.Singleton);
     registrator.Register(typeof(IConfigProvider <>), typeof(DefaultConfigProvider <>), Reuse.Singleton);
 }
Esempio n. 9
0
        protected override void Load(IRegistrator builder, ITypeFinder typeFinder, SiteConfig config)
        {
            //Register for Data Repositories
            builder.Register <IProjectTypeRepository, ProjectTypeRepository>(Reuse.InWebRequest);
            builder.Register <IProjectRepository, ProjectRepository>(Reuse.InWebRequest);

            //Register for Data Services
            builder.Register <ITmcMainService, TmcMainService>(Reuse.InWebRequest);
        }
Esempio n. 10
0
 public static IRegistrator SetupViewModels(this IRegistrator registrator)
 {
     registrator.Register <ILightsOutGameViewModel, LightsOutGameViewModel>();
     registrator.Register <ISwitchViewModel, SwitchViewModel>();
     registrator.Register <ILevelsLoader, LevelsLoader>();
     registrator.RegisterDelegate <Func <HttpClient> >(r => () => new HttpClient());
     registrator.RegisterDelegate <Func <ISwitchViewModel> >(r => () => r.Resolve <ISwitchViewModel>());
     return(registrator);
 }
        public CompositionRoot(IRegistrator registrator)
        {
            registrator.Register <IUnitOfWorkManager, UnitOfWorkManager>(Reuse.InWebRequest);
            registrator.Register <IClaimService, ClaimService>(Reuse.InWebRequest);

            //UnitOfWork will be disposed each time, so it should get a new instance each time
            registrator.Register <IUnitOfWork, UnitOfWork>(setup: Setup.With(allowDisposableTransient: true));
            registrator.Register <IRepository <ClaimDTO, int>, GeneralRepository <ClaimDTO, int> >(setup: Setup.With(allowDisposableTransient: true));
            registrator.Register <DbContext, ApplicationDbContext>(setup: Setup.With(allowDisposableTransient: true));
        }
Esempio n. 12
0
        // If you need the whole container then change parameter type from IRegistrator to IContainer
        public CompositionRoot(IRegistrator r)
        {
            r.Register <IHotelServices, HotelServices>(Reuse.Singleton);
            r.Register <IDataServices, DataServices>(Reuse.Transient);
            // r.Register<IScopedService, ScopedService>(Reuse.InCurrentScope);

            var assemblies = new[] { typeof(DataServices).GetAssembly() };

            r.RegisterExports(assemblies);
        }
Esempio n. 13
0
        private static void RegisterComponents(this IRegistrator container)
        {
            container.Register(
                Made.Of(
                    () => Arg.Of <ILoggerFactory>().CreateLogger(Arg.Index <Type>(0)),
                    request => request.Parent.ImplementationType
                    )
                );

            container.Register <INHibernateInstaller, NHibInstaller>(Reuse.Singleton);
        }
Esempio n. 14
0
        // If you need the whole container then change parameter type from IRegistrator to IContainer
        public CompositionRoot(IRegistrator r)
        {
            r.Register <ISingletonService, SingletonService>(Reuse.Singleton);
            r.Register <ITransientService, TransientService>(Reuse.Transient);
            r.Register <IScopedService, ScopedService>(Reuse.InCurrentScope);

            // optional: MEF based auto-wiring
            var assemblies = new[] { typeof(ExportedService).GetAssembly() };

            r.RegisterExports(assemblies);
        }
Esempio n. 15
0
        public CompositionRoot(IRegistrator r)
        {
            // Services
            r.Register <BroadcastService, BroadcastService>(Reuse.Singleton);
            r.Register <GameService, GameService>(Reuse.Singleton);
            r.Register <UserService, UserService>(Reuse.Singleton);

            // Repositories
            r.Register <IApiRepository, ApiRepository>(Reuse.Singleton);
            r.Register <ICommunityRepository, CommunityRepository>(Reuse.Singleton);
        }
Esempio n. 16
0
        // If you need the whole container then change the parameter type from IRegistrator to IContainer
        public static void RegisterMyBusinessLogic(this IRegistrator r)
        {
            r.Register <ISingletonService, SingletonService>(Reuse.Singleton);
            r.Register <ITransientService, TransientService>(Reuse.Transient);
            r.Register <IScopedService, ScopedService>(Reuse.InCurrentScope);

            r.Register <IExportedService, ExportedService>();

            // optional: registering MEF Exported services
            //var assemblies = new[] { typeof(ExportedService).GetAssembly() };
            //r.RegisterExports(assemblies);
        }
Esempio n. 17
0
        // If you need the whole container then change the parameter type from IRegistrator to IContainer
        public MyCompositionRoot(IRegistrator r)
        {
            r.Register <ISingletonService, SingletonService>(Reuse.Singleton);
            r.Register <ITransientService, TransientService>(Reuse.Transient);
            r.Register <IScopedService, ScopedService>(Reuse.InCurrentScope);

            r.Register <IExportedService, ExportedService>();

            // optional: registering MEF Exported services
            //var assemblies = new[] { typeof(ExportedService).GetAssembly() };
            //r.RegisterExports(assemblies);
        }
Esempio n. 18
0
 public QueueConfigurator SetConfigurationProvider <TConfiguration>(TConfiguration configuration = default(TConfiguration))
     where TConfiguration : class, IMessagingConfiguration
 {
     if (configuration == null)
     {
         _registrator.Register <IMessagingConfiguration, TConfiguration>();
     }
     else
     {
         _registrator.RegisterInstance <IMessagingConfiguration>(configuration);
     }
     return(this);
 }
Esempio n. 19
0
        public CompositionRoot(IRegistrator registrator)
        {
            registrator.Register <IOrderService, OrderService>();
            registrator.Register <ICustomerService, CustomerService>();

            //For components
            registrator.RegisterRepository();

            //For assembly scan
            //container.Register<ILogger, Serilog>() ;
            //    //var assemblies = new[] { typeof(ExportedService).GetAssembly() };
            //    //container.RegisterMany(assemblies);
        }
Esempio n. 20
0
        public WebApiCompositionRoot(IRegistrator registrator, IOptions <ModeOptions> options)
        {
            BusinessLayerComposition.ModeOptions = options.Value;
            var blComposition = new BusinessLayerComposition(registrator);

            registrator.Register <RabbitMqBrokerSender>(Reuse.Singleton);
            registrator.Register <IBrokerSender, EasyNetQBrokerSender>(Reuse.InCurrentScope);

            registrator.Register <ICurrentUserProvider, CurrentUserProvider>(Reuse.InCurrentScope);

            registrator.Register <IArgumentParser, JsonArgumentParser>();
            registrator.Register <IArgumentParser, PrimitiveArgumentParser>();
        }
Esempio n. 21
0
        public static void Load(IRegistrator builder)
        {
            builder.Register <PageNavigator>(Reuse.Singleton);
            builder.Register <PageLocator>(Reuse.Singleton);
            builder.Register <SafeCommandFactory>(Reuse.Singleton);
            builder.Register <ICache, RedisService>(Reuse.Singleton);

            builder.Register <ICoursesRepository, CoursesRepository>(Reuse.Singleton);
            builder.Register <IGuidRepository, GuidRepository>(Reuse.Singleton);
            builder.Register <INavigationRepository, NavigationRepository>(Reuse.Singleton);
            builder.Register <IPropertiesRepository, PropertiesRepository>(Reuse.Singleton);

            builder.Register <BasePage>();
            builder.Register <BaseViewModel>();
        }
Esempio n. 22
0
        private static void RegisterFactoryMethods(IRegistrator registrator, ExportedRegistrationInfo factoryInfo)
        {
            // NOTE: Cast is required for NET35
            var members = factoryInfo.ImplementationType.GetAll(t =>
                                                                t.DeclaredMethods.Cast <MemberInfo>().Concat(
                                                                    t.DeclaredProperties.Cast <MemberInfo>().Concat(
                                                                        t.DeclaredFields.Cast <MemberInfo>())));

            foreach (var member in members)
            {
                var attributes = member.GetAttributes().ToArrayOrSelf();
                if (!IsExportDefined(attributes))
                {
                    continue;
                }

                var memberReturnType = member.GetReturnTypeOrDefault();
                var registrationInfo = GetRegistrationInfoOrDefault(memberReturnType, attributes).ThrowIfNull();

                var factoryExport      = factoryInfo.Exports[0];
                var factoryServiceInfo = member.IsStatic() ? null :
                                         ServiceInfo.Of(factoryExport.ServiceType, IfUnresolved.ReturnDefault, factoryExport.ServiceKeyInfo.Key);

                var factoryMethod = FactoryMethod.Of(member, factoryServiceInfo);
                var factory       = registrationInfo.CreateFactory(Made.Of(_ => factoryMethod));

                var serviceExports = registrationInfo.Exports;
                for (var i = 0; i < serviceExports.Length; i++)
                {
                    var export = serviceExports[i];
                    registrator.Register(factory,
                                         export.ServiceType, export.ServiceKeyInfo.Key, IfAlreadyRegistered.AppendNotKeyed, false);
                }
            }
        }
Esempio n. 23
0
        private void RegisterBaseOnLifetimeScope(Type interfaceType, Type implementerType)
        {
            var regInfo       = implementerType.GetRegistrationInfoFromCustomAttribues();
            var lifeTimeScope = regInfo.Item1;
            var name          = regInfo.Item2;

            switch (lifeTimeScope)
            {
            case LifetimeScopeType.SingleInstance:
                _registrator.RegisterAsSingleInstance(interfaceType, implementerType, name);
                break;

            case LifetimeScopeType.InstancePerLifetimeScope:
                _registrator.RegisterAsPerLifetimeScope(interfaceType, implementerType, name);
                break;

            case LifetimeScopeType.InstancePerRequest:
                _registrator.RegisterAsPerRequest(interfaceType, implementerType, name);
                break;

            case LifetimeScopeType.InstancePerDependency:
            default:
                _registrator.Register(interfaceType, implementerType, name);
                break;
            }
        }
Esempio n. 24
0
        public static void Intercept <TService, TInterceptor>(this IRegistrator registrator, object serviceKey = null)
            where TInterceptor : class, IInterceptor
        {
            var serviceType = typeof(TService);

            Type proxyType;

            if (serviceType.IsInterface())
            {
                proxyType = ProxyBuilder.CreateInterfaceProxyTypeWithTargetInterface(
                    serviceType, ArrayTools.Empty <Type>(), ProxyGenerationOptions.Default);
            }
            else if (serviceType.IsClass())
            {
                proxyType = ProxyBuilder.CreateClassProxyType(
                    serviceType, ArrayTools.Empty <Type>(), ProxyGenerationOptions.Default);
            }
            else
            {
                throw new ArgumentException(string.Format(
                                                "Intercepted service type {0} is not a supported: it is nor class nor interface", serviceType));
            }

            var decoratorSetup = serviceKey == null
                ? Setup.DecoratorWith(useDecorateeReuse : true)
                : Setup.DecoratorWith(r => serviceKey.Equals(r.ServiceKey), useDecorateeReuse: true);

            registrator.Register(serviceType, proxyType,
                                 made: Made.Of(type => type.PublicConstructors().SingleOrDefault(c => c.GetParameters().Length != 0),
                                               Parameters.Of.Type <IInterceptor[]>(typeof(TInterceptor[]))),
                                 setup: decoratorSetup);
        }
Esempio n. 25
0
 public void RegisterIfSatisfiesFilter(Type type)
 {
     if (_typeFilter(type))
     {
         _registrator.Register(type, _context);
     }
 }
        public static void RegisterInterfaceInterceptor(this IRegistrator registrator, Type serviceType, Type interceptorType, int order, object serviceKey = null)
        {
            //if (!serviceType.IsInterface)
            //    throw new ArgumentException(string.Format("Intercepted service type {0} is not an interface", serviceType));

            Type proxyType;

            Type[] targetInterfaces = new Type[0];

            /*if (targetInterface== null)
             * {
             *  targetInterfaces = new Type[0];
             * }
             * else
             * {
             *  targetInterfaces = new Type[] { targetInterface };
             * }*/
            if (serviceType.IsInterface)
            {
                proxyType = ProxyBuilder.Value.CreateInterfaceProxyTypeWithTargetInterface(serviceType, targetInterfaces, ProxyGenerationOptions.Default);
                //proxyType = ProxyBuilder.Value.CreateInterfaceProxyTypeWithTarget(serviceType, targetInterfaces, ProxyGenerationOptions.Default);
                //proxyType = ProxyBuilder.Value.CreateClassProxyType(serviceType, targetInterfaces, ProxyGenerationOptions.Default);
                //proxyType = ProxyBuilder.Value.CreateInterfaceProxyTypeWithTarget(serviceType, targetInterfaces, targetType, ProxyGenerationOptions.Default);
                //proxyType = ProxyBuilder.Value.CreateInterfaceProxyTypeWithoutTarget(serviceType, targetInterfaces, ProxyGenerationOptions.Default);
            }
            else
            {
                proxyType = ProxyBuilder.Value.CreateClassProxyType(serviceType, targetInterfaces, ProxyGenerationOptions.Default);
                //proxyType = ProxyBuilder.Value.CreateClassProxyTypeWithTarget(serviceType, targetInterfaces, ProxyGenerationOptions.Default);
            }
            var interceptorArrayType = Array.CreateInstance(interceptorType, 0).GetType();

            registrator.Register(serviceType, proxyType, made: Parameters.Of.Type(interceptorArrayType), setup: Setup.DecoratorWith(order: order, condition: SpecialCondition) /*, serviceKey: serviceKey*/);
        }
Esempio n. 27
0
 /// <summary>
 /// Registers a service.
 /// </summary>
 /// <typeparam name="TService">The type, base type or interface of the service.</typeparam>
 /// <typeparam name="TImplementation">The concrete implementation of the <typeparamref name="TService"/>.</typeparam>
 /// <param name="registrator">The registrator.</param>
 /// <param name="lifecycle">The lifecycle used in the creating/locating the service.</param>
 /// <param name="behavior">The behavior to take when there is a duplicate registration.</param>
 public static void Register <TService, TImplementation>(this IRegistrator registrator,
                                                         ILifecycle lifecycle,
                                                         RegistrationConflictBehavior behavior)
     where TImplementation : TService
 {
     registrator.Register(typeof(TService), typeof(TImplementation), lifecycle, behavior);
 }
Esempio n. 28
0
        public static void Intercept <TService, TInterceptor>(this IRegistrator registrator, object serviceKey = null)
            where TInterceptor : class, IInterceptor
        {
            var serviceType = typeof(TService);

            Type proxyType;

            if (serviceType.IsInterface())
            {
                proxyType = _proxyBuilder.CreateInterfaceProxyTypeWithTargetInterface(
                    serviceType, ArrayTools.Empty <Type>(), ProxyGenerationOptions.Default);
            }
            else if (serviceType.IsClass())
            {
                proxyType = _proxyBuilder.CreateClassProxyTypeWithTarget(
                    serviceType, ArrayTools.Empty <Type>(), ProxyGenerationOptions.Default);
            }
            else
            {
                throw new ArgumentException(
                          $"Intercepted service type {serviceType} is not a supported, cause it is nor a class nor an interface");
            }

            registrator.Register(serviceType, proxyType,
                                 made: Made.Of(pt => pt.PublicConstructors().FindFirst(ctor => ctor.GetParameters().Length != 0),
                                               Parameters.Of.Type <IInterceptor[]>(typeof(TInterceptor[]))),
                                 setup: Setup.DecoratorOf(useDecorateeReuse: true, decorateeServiceKey: serviceKey));
        }
 public void Load(IRegistrator registrator)
 {
     registrator.RegisterAll(HelperModule.Instance);
     registrator.Register <IDatabaseFactory, DatabaseFactory>(Reuse.Singleton);
     registrator.RegisterForAllImplementedInterfaces(_repositories, Reuse.Singleton);
     registrator.RegisterInitializer <IDatabaseRepository>(InitializeConnectionInfoForRepository);
 }
Esempio n. 30
0
 /// <summary>
 /// Registers a service.
 /// </summary>
 /// <param name="registrator">The registrator.</param>
 /// <param name="serviceType">The type, base type or interface of the service to register.</param>
 /// <param name="implementationType">The implementation of the serviceType.</param>
 /// <param name="lifecycle">The lifecycle used in the creating/locating the service.</param>
 public static void Register(this IRegistrator registrator,
                             Type serviceType,
                             Type implementationType,
                             ILifecycle lifecycle)
 {
     registrator.Register(serviceType, implementationType, lifecycle, RegistrationConflictBehavior.Default);
 }
        /// <summary>
        /// Sets the default implementations.
        /// </summary>
        /// <param name="container">The container.</param>
        private static void SetDefaultImplementations(IRegistrator container)
        {
            // TODO auto-register at least from Controllers and NSI WS
            container.Register<IStructureWriterFactory, SdmxStructureXmlFactory>(Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Keep);
            container.Register<IRetrieverManager, RetrieverManager>(Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Keep);
            container.Register<IStructureWriterFactory, SdmxStructureXmlFactory>(Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Keep);
            container.Register<IStructureWriterManager, StructureWriterManager>(Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Keep, made: FactoryMethod.ConstructorWithResolvableArguments);

            container.Register<IDataWriterFactory, LazyDataWriterFactory>(Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Keep);
            container.Register<IDataWriterManager, DataWriterManager>(Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Keep);
            container.Register<IDataRequestController, DataRequestController>(Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Keep);
            container.Register<IStructureRequestController, StructureRequestController>(Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Keep);
            container.Register<IMessageBuilderManager, MessageBuilderManager>(Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Keep);
            container.Register<INSIStdV21Service, NSIStdV21Service>(Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Keep);
            container.Register<INSIEstatV20Service, NsiEstatV20Service>(Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Keep);
            container.Register<INSIStdV20Service, NsiStdV20Service>(Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Keep);
            container.Register<IWadlProvider, WadlProvider>(Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Keep);
            container.Register<IStaticWsdlService, StaticWsdlService>(Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Keep);
            container.Register<IDataResource, DataResource>(Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Keep);
            container.Register<IStructureResource, StructureResource>(Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Keep);
            container.Register<IMessageFaultSoapBuilderFactory, MessageFaultSoapBuilderFactory>(Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Keep);
            container.Register<IDataQueryVisitorFactory, DataQueryVisitorFactory>(Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Keep);
            container.Register<IDataflowPrincipalManager, DataflowPrincipalManager>(Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Keep);
            container.Register<WsdlRegistry>(Reuse.Singleton);
        }