Beispiel #1
0
        static void RegOrganizations(IRegistrator container)
        {
            var ns = typeof(OrganizationBase.OrganizationEntity).Namespace;

            var types = typeof(OrganizationBase.OrganizationEntity).Assembly.GetLoadedTypes().Where(i =>
            {
                return(i.Namespace == ns && !i.IsInterface && !i.IsAbstract &&
                       (i.Name.EndsWith("Repository") || i.Name.EndsWith("Service") || i.Name.EndsWith("Builder") ||
                        i.Name.EndsWith("Validator") || i.Name.EndsWith("Authorization")));
            }
                                                                                                    );

            container.RegisterMany(types, Reuse.Singleton, serviceTypeCondition: s => s.IsInterface,
                                   ifAlreadyRegistered: IfAlreadyRegistered.Throw);

            var ns1 = typeof(Organizations.Organization).Namespace;

            types = typeof(Organizations.Organization).Assembly.GetLoadedTypes().Where(i =>
            {
                return(i.Namespace == ns1 && !i.IsInterface && !i.IsAbstract &&
                       (i.Name.EndsWith("Repository") || i.Name.EndsWith("Service") || i.Name.EndsWith("Builder") ||
                        i.Name.EndsWith("Validator") || i.Name.EndsWith("Authorization")) &&
                       i.Name != "UserRepository" &&
                       i.Name != "UniqueUserDecoratorForUserRepository" &&
                       i.Name != "UserChangeBlockerWhenExternallyOwned" &&
                       i.Name != "ConnOrganizationUserRepository");
            }
                                                                                       );

            container.RegisterMany(types, Reuse.Singleton, serviceTypeCondition: s => s.IsInterface,
                                   ifAlreadyRegistered: IfAlreadyRegistered.Replace);
        }
Beispiel #2
0
        public static void RegisterServices(IRegistrator registrator)
        {
            // NOTE: Registers ISession provider to work with injected Request
            registrator.Register(Made.Of(() => GetSession(Arg.Of <HttpRequestMessage>())));

            registrator.RegisterMany <ConsoleLogger>();
            registrator.RegisterMany <NewsProvider>();
        }
Beispiel #3
0
            private static void RegIntegrations(IRegistrator container)
            {
                var types = Assembly.GetExecutingAssembly().GetLoadedTypes()
                            .Where((i) => i.Namespace == "Integrations" && !i.IsInterface && !i.IsAbstract && i.Name.EndsWith("Service"));

                container.RegisterMany(types, serviceTypeCondition: (s) => s.IsInterface, ifAlreadyRegistered: IfAlreadyRegistered.Replace);

                // Register providers
                var providerTypes = Assembly.GetExecutingAssembly().GetLoadedTypes().Where(
                    i => i.Namespace == "Integrations" && !i.IsInterface && !i.IsAbstract && i.Name.EndsWith("Provider")
                    );

                container.RegisterMany(providerTypes, Reuse.Scoped, serviceTypeCondition: s => s.IsInterface && s.Name != "ICalendarSyncProvider" && s.Name != "IIntegrationProvider", ifAlreadyRegistered: IfAlreadyRegistered.Throw);
            }
Beispiel #4
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);
            }
Beispiel #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);
            }
Beispiel #6
0
        public static void Load(IRegistrator builder)
        {
            builder.Register <BotService>(Reuse.Singleton);
            builder.Register <AccountService>(Reuse.Singleton);
            builder.Register <GuidService>(Reuse.Singleton);
            builder.Register <StateSynchronizer>(Reuse.Singleton);
            builder.Register <UserProvider>(Reuse.Singleton);

            builder.Register <IRootPage, TelegramRootPage>(Reuse.Singleton);
            builder.Register <ILoggerService, LoggerService>(Reuse.Singleton);
            builder.Register <IUserDataRepository, UserDataRepository>(Reuse.Singleton);
            builder.Register <IDocumentDataRepository, DocumentDataRepository>(Reuse.Singleton);

            builder.RegisterMany(GetAssemblyPageTypes());
            builder.RegisterMany(GetAssemblyViewModelsTypes());
        }
Beispiel #7
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 <>));
        }
Beispiel #8
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);
        }
Beispiel #9
0
            static void RegisterRepositories(IRegistrator container)
            {
                var ns    = typeof(CUsers.Domain.UserEventRepository).Namespace;
                var types = typeof(CUsers.Domain.UserEventRepository).Assembly.GetLoadedTypes().Where(
                    (i) => i.Namespace == ns && !i.IsInterface && !i.IsAbstract && i.Name.EndsWith("Repository")
                    );

                container.RegisterMany(types, Reuse.Singleton, serviceTypeCondition: (s) => s.IsInterface,
                                       ifAlreadyRegistered: IfAlreadyRegistered.Throw);
            }
Beispiel #10
0
            static void RegisterApplicationServices(IRegistrator container)
            {
                var ns    = typeof(CUsers.ApplicationServices.IUserService).Namespace;
                var types = typeof(CUsers.ApplicationServices.IUserService).Assembly.GetLoadedTypes().Where(
                    (i) => i.Namespace == ns && !i.IsInterface && !i.IsAbstract &&
                    (i.Name.EndsWith("Service") || i.Name.EndsWith("Handler") || i.Name.EndsWith("Reader"))
                    );

                container.RegisterMany(types, Reuse.Singleton, serviceTypeCondition: (s) => s.IsInterface,
                                       ifAlreadyRegistered: IfAlreadyRegistered.Throw);
            }
Beispiel #11
0
            private static void RegisterImplementations(IRegistrator container)
            {
                var ns = typeof(Users.IUniqueUserService).Namespace;

                container.RegisterMany(typeof(Users.IUniqueUserService).GetAssembly().GetLoadedTypes().Where(i =>
                {
                    return(i.Namespace == ns && !i.IsInterface && !i.IsAbstract &&
                           ((i.Name.EndsWith("Service") && i.Name != "UniqueUserService") ||
                            i.Name.EndsWith("Authorization")
                           ));
                }), Reuse.Singleton, serviceTypeCondition: s => s.IsInterface && s.Namespace == ns,
                                       ifAlreadyRegistered: IfAlreadyRegistered.Throw
                                       );
            }
Beispiel #12
0
                public static void Load(IRegistrator container)
                {
                    var ns = typeof(ScheduledWork.ScheduledWorkService).Namespace;

                    container.RegisterMany(typeof(ScheduledWork.ScheduledWorkService).Assembly
                                           .GetLoadedTypes().Where(i =>
                    {
                        return(i.Namespace == ns && !i.IsInterface && !i.IsAbstract &&
                               i.Name.EndsWith("Service"));
                    }
                                                                   ), Reuse.Singleton, serviceTypeCondition: s => s.IsInterface && s.Namespace == ns,
                                           ifAlreadyRegistered: IfAlreadyRegistered.Throw
                                           );
                }
Beispiel #13
0
                private static void RegisterApplicationServices(IRegistrator container)
                {
                    var theAssembly = typeof(Background.ScopedBackgroundTask).Assembly;
                    var ns          = typeof(Background.ScopedBackgroundTask).Namespace;

                    var types = theAssembly.GetLoadedTypes()
                                .Where((t) =>
                                       t.Namespace == ns && !t.IsAbstract && !t.IsInterface && t.Name.EndsWith("Service"));

                    container.RegisterMany(types, reuse: Reuse.Singleton, serviceTypeCondition: (s) => s.IsInterface && s.Namespace == ns,
                                           ifAlreadyRegistered: IfAlreadyRegistered.Throw);

                    // Register the scope wrapper
                    container.Register(typeof(Background.ScopedBackgroundTask), reuse: Reuse.Transient);
                }
Beispiel #14
0
        static void RegC(IRegistrator container)
        {
            var ns    = typeof(RM.AccountService).Namespace;
            var types = typeof(RM.AccountService).Assembly.GetLoadedTypes().Where(i =>
            {
                return(i.Namespace == ns && !i.IsInterface && !i.IsAbstract &&
                       (i.Name.EndsWith("Repository") || i.Name.EndsWith("Service") ||
                        i.Name.EndsWith("Validator") || i.Name.EndsWith("Authorization")
                       ));
            }
                                                                                  );

            container.RegisterMany(types, Reuse.Singleton, serviceTypeCondition: s => s.IsInterface,
                                   ifAlreadyRegistered: IfAlreadyRegistered.Throw);
        }
Beispiel #15
0
            private static void RegisterConnWebHooks(IRegistrator container)
            {
                var ns = typeof(Conn.Service.ConnWebHooksController).Namespace;

                container.RegisterMany(typeof(Conn.Service.ConnWebHooksController).Assembly.GetLoadedTypes()
                                       .Where(type =>
                {
                    return(type.Namespace == ns && !type.IsInterface && !type.IsAbstract &&
                           (type.Name.EndsWith("Service") || type.Name.EndsWith("Validator") ||
                            type.Name.EndsWith("Handler")
                           ));
                }
                                              ), Reuse.Singleton, serviceTypeCondition: s => s.IsInterface && s.Namespace == ns,
                                       ifAlreadyRegistered: IfAlreadyRegistered.Throw
                                       );
            }
Beispiel #16
0
        static void RegConnAdapterLoad(IRegistrator container)
        {
            container.Register <IConnClient, ConnClient>(reuse: Reuse.Singleton,
                                                         ifAlreadyRegistered: IfAlreadyRegistered.Throw);
            container.Register <IConnErrorFactory, ConnErrorFactory>(reuse: Reuse.Singleton,
                                                                     ifAlreadyRegistered: IfAlreadyRegistered.Throw);
            container.Register <IConnPublicApiClientFactory, ConnPublicApiClientFactory>(
                reuse: Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Throw);
            container.Register <IConnCertificateStorage, ConnCertificateStorage>(reuse: Reuse.Singleton,
                                                                                 ifAlreadyRegistered: IfAlreadyRegistered.Throw);

            var ns    = typeof(IConnClient).Namespace;
            var types = typeof(IConnClient).Assembly.GetLoadedTypes().Where(i =>
            {
                return(i.Namespace == ns && !i.IsInterface && !i.IsAbstract && i.Name.EndsWith("Service"));
            }
                                                                            );

            container.RegisterMany(types, Reuse.Singleton, serviceTypeCondition: s => s.IsInterface && s.Namespace == ns,
                                   ifAlreadyRegistered: IfAlreadyRegistered.Throw);
        }
Beispiel #17
0
        public void RegisterDependencies(IRegistrator registrar)
        {
            // settings register for access across app
            registrar.Register <IDatabaseSettings, DatabaseSettings>(reuse: Reuse.Singleton, ifAlreadyRegistered: IfAlreadyRegistered.Keep);
            //caching
            registrar.Register <ICacheProvider, MemoryCacheProvider>(reuse: Reuse.Singleton);
            registrar.Register <ICacheAccountant, CacheAccountant>(reuse: Reuse.Transient);
            //events
            registrar.Register <IEventPublisherService, EventPublisherService>(reuse: Reuse.Singleton);
            //file access
            registrar.Register <ILocalFileProvider, LocalFileProvider>(reuse: Reuse.Singleton);
            //localizer
            registrar.Register <ILocalizer, Localizer>(reuse: Reuse.ScopedOrSingleton);
            //view engine & friends
            registrar.Register <IViewAccountant, ViewAccountant>(reuse: Reuse.Singleton);
            registrar.Register <IAppViewEngine, DefaultAppViewEngine>(reuse: Reuse.Singleton);
            //media
            registrar.Register <IImageProcessor, ImageProcessor>(reuse: Reuse.Singleton);
            registrar.Register <IMediaAccountant, MediaAccountant>(reuse: Reuse.Singleton);
            //plugin loader
            registrar.Register <IPluginAccountant, PluginAccountant>(reuse: Reuse.ScopedOrSingleton);
            //model mapper
            registrar.Register <IModelMapper, ModelMapper>(reuse: Reuse.Singleton);
            //routetemplate parser
            registrar.Register <IRouteTemplateParser, RouteTemplateParser>(reuse: Reuse.Singleton);
            registrar.Register <IDynamicRouteProvider, DynamicRouteProvider>(reuse: Reuse.ScopedOrSingleton);
            //themes
            registrar.Register <IThemeProvider, ThemeProvider>(reuse: Reuse.Singleton);
            //view compoenent
            registrar.Register <IViewComponentManager, ViewComponentManager>(reuse: Reuse.ScopedOrSingleton);
            //search query
            registrar.Register <ISearchQueryParserService, SearchQueryParserService>(reuse: Reuse.Scoped);
            //html processor
            registrar.Register <IHtmlProcessor, HtmlProcessor>(reuse: Reuse.Singleton);
            //email sender
            registrar.Register <IEmailSender, EmailSender>(reuse: Reuse.Transient);
            //bundler
            registrar.Register <IBundleService, BundleService>(reuse: Reuse.Transient);
            //minifier
            registrar.Register <IMinifier, Minifier>(reuse: Reuse.Transient);
            //interceptor
            registrar.Register <IInterceptorService, InterceptorService>(reuse: Reuse.Singleton);
            //conection accountant
            registrar.Register <IConnectionAccountant, ConnectionAccountant>(Reuse.Transient);
            var asm      = AssemblyLoader.GetAppDomainAssemblies();
            var allTypes = asm.Where(x => !x.IsDynamic).SelectMany(x =>
            {
                try
                {
                    return(x.GetTypes());
                }
                catch (ReflectionTypeLoadException)
                {
                    return(new Type[0]);
                }
            })
                           .Where(x => x.IsPublic && !x.IsAbstract).ToList();

            //find all the model factories
            var allModelFactories = allTypes
                                    .Where(type => type.GetInterfaces()
                                           .Any(x => x.IsAssignableTo(typeof(IModelFactory))));// which implementing some interface(s)

            //all consumers which are not interfaces
            registrar.RegisterMany(allModelFactories);

            //capability providers
            var allCapabilityProviderTypes = allTypes
                                             .Where(type => type.GetInterfaces()
                                                    .Any(x => x.IsAssignableTo(typeof(ICapabilityProvider))));// which implementing some interface(s)

            //all providers which are not interfaces
            registrar.RegisterMany(allCapabilityProviderTypes);

            //tasks
            var allTaskTypes = allTypes
                               .Where(type => type.GetInterfaces()
                                      .Any(x => x.IsAssignableTo(typeof(ITask))));// which implementing some interface(s)

            //all providers which are not interfaces
            registrar.RegisterMany <ITask>(allTaskTypes, type => type.FullName);

            //interceptors
            var allInterceptorTypes = allTypes
                                      .Where(type => type.GetInterfaces()
                                             .Any(x => x.IsAssignableTo(typeof(IInterceptor))));// which implementing some interface(s)

            //all providers which are not interfaces
            registrar.RegisterMany <IInterceptor>(allInterceptorTypes, type => type.FullName);

            //currency providers
            var allCurrencyProviders = allTypes
                                       .Where(type => type.IsPublic &&                                     // get public types
                                              type.GetInterfaces()
                                              .Any(x => x.IsAssignableTo(typeof(ICurrencyRateProvider)))); // which implementing some interface(s)

            //all providers which are not interfaces
            registrar.RegisterMany <ICurrencyRateProvider>(allCurrencyProviders, type => type.FullName);

            //find all the event captures
            var allEventCaptures = allTypes
                                   .Where(type => type.GetInterfaces()
                                          .Any(x => x.IsAssignableTo(typeof(IEventCapture))));// which implementing some interface(s)

            //registrar.RegisterMany<IEventCapture>();
            //all consumers which are not interfaces
            registrar.RegisterMany <IEventCapture>(allEventCaptures, type => type.FullName);

            //services
            //to register services, we need to get all types from services assembly and register each of them;
            var serviceAssembly = asm.First(x => x.FullName.Contains("EvenCart.Services,"));
            var serviceTypes    = serviceAssembly.GetTypes().
                                  Where(type => type.IsPublic &&           // get public types
                                        !type.IsAbstract &&                // which are not interfaces nor abstract
                                        type.GetInterfaces().Length != 0); // which implementing some interface(s)

            registrar.RegisterMany(serviceTypes, Reuse.Transient);

            registrar.Register <IFormatterService, FormatterService>(Reuse.Singleton,
                                                                     ifAlreadyRegistered: IfAlreadyRegistered.Replace);

            //find all event consumer types
            var allConsumerTypes = allTypes
                                   .Where(type => type.GetInterfaces()
                                          .Any(x => x.IsAssignableTo(typeof(IFoundationEvent))));// which implementing some interface(s)

            //all consumers which are not interfaces
            registrar.RegisterMany(allConsumerTypes);

            //components
            //find all event consumer types
            var allComponents = allTypes
                                .Where(type => type.IsClass && type.IsAssignableTo(typeof(FoundationComponent)));// which implementing some interface(s)

            registrar.RegisterMany(allComponents, Reuse.Transient);

            //settings
            var allSettingTypes = TypeFinder.ClassesOfType <ISettingGroup>();

            foreach (var settingType in allSettingTypes)
            {
                var type = settingType;
                registrar.RegisterDelegate(type, resolver =>
                {
                    var storeId = ApplicationEngine.CurrentStore?.Id ?? 0;
                    return(resolver.Resolve <ISettingService>().GetSettings(type, storeId));
                }, reuse: Reuse.Transient);
            }

            registrar.Register <IAppAuthenticationService, AuthenticationService>(reuse: Reuse.Transient);

            var allModules = TypeFinder.ClassesOfType <IPlugin>();

            foreach (var moduleType in allModules)
            {
                var type = moduleType;
                registrar.Register(type, reuse: Reuse.Singleton);
            }
        }