Example #1
0
        public static ServiceRegistryService GetLocalServiceRegistryService(DataSettings dataSettings, IApplicationNameProvider appNameProvider, string assemblySearchPattern, ILogger logger = null)
        {
            logger = logger ?? Log.Default;
            DaoRepository             repo        = dataSettings.GetSysDaoRepository(logger, nameof(FileService));
            FileService               fileService = new FileService(repo);
            AssemblyServiceRepository assRepo     = new AssemblyServiceRepository();

            assRepo.Database = dataSettings.GetSysDatabaseFor(assRepo);
            assRepo.EnsureDaoAssemblyAndSchema();
            AssemblyService           assemblyService     = new AssemblyService(DataSettings.Current, fileService, assRepo, appNameProvider);
            ServiceRegistryRepository serviceRegistryRepo = new ServiceRegistryRepository();

            serviceRegistryRepo.Database = dataSettings.GetSysDatabaseFor(serviceRegistryRepo);
            serviceRegistryRepo.EnsureDaoAssemblyAndSchema();
            ServiceRegistryService serviceRegistryService = new ServiceRegistryService(
                fileService,
                assemblyService,
                serviceRegistryRepo,
                dataSettings.GetSysDaoRepository(logger),
                new AppConf {
                Name = appNameProvider.GetApplicationName()
            }
                )
            {
                AssemblySearchPattern = assemblySearchPattern
            };

            return(serviceRegistryService);
        }
Example #2
0
        private static void SetVaultDatabase()
        {
            DataSettings dataSettings = DataSettings.Default;

            Vault.SystemVaultDatabase = dataSettings.GetSysDatabaseFor(typeof(Vault), "System");
            Vault.SystemVaultDatabase.TryEnsureSchema <Vault>();
        }
        // --

        public static ServiceRegistry Create()
        {
            DataSettings dataSettings      = DataSettings.Current;
            string       databasesPath     = dataSettings.GetSysDatabaseDirectory().FullName;
            string       userDatabasesPath = Path.Combine(databasesPath, "UserDbs");

            AppConf                           conf         = new AppConf(BamConf.Load(ServiceConfig.ContentRoot), ServiceConfig.ProcessName.Or(RegistryName));
            UserManager                       userMgr      = conf.UserManagerConfig.Create();
            DaoUserResolver                   userResolver = new DaoUserResolver();
            DaoRoleResolver                   roleResolver = new DaoRoleResolver();
            SQLiteDatabaseProvider            dbProvider   = new SQLiteDatabaseProvider(databasesPath, Log.Default);
            ApplicationRegistrationRepository coreRepo     = new ApplicationRegistrationRepository();

            dbProvider.SetDatabases(coreRepo);
            dbProvider.SetDatabases(userMgr);
            userMgr.Database.TryEnsureSchema(typeof(UserAccounts.Data.User), Log.Default);
            userResolver.Database = userMgr.Database;
            roleResolver.Database = userMgr.Database;

            ServiceRegistryRepository serviceRegistryRepo = new ServiceRegistryRepository();

            serviceRegistryRepo.Database = dataSettings.GetSysDatabaseFor(serviceRegistryRepo);
            serviceRegistryRepo.EnsureDaoAssemblyAndSchema();

            DaoRoleProvider           daoRoleProvider = new DaoRoleProvider(userMgr.Database);
            RoleService               coreRoleService = new RoleService(daoRoleProvider, conf);
            AssemblyServiceRepository assSvcRepo      = new AssemblyServiceRepository();

            assSvcRepo.Database = dataSettings.GetSysDatabaseFor(assSvcRepo);
            assSvcRepo.EnsureDaoAssemblyAndSchema();

            ConfigurationService configSvc     = new ConfigurationService(coreRepo, conf, userDatabasesPath);
            CompositeRepository  compositeRepo = new CompositeRepository(coreRepo);
            SystemLoggerService  loggerSvc     = new SystemLoggerService(conf);

            dbProvider.SetDatabases(loggerSvc);
            loggerSvc.SetLogger();

            ServiceRegistry reg = (ServiceRegistry)(new ServiceRegistry())
                                  .ForCtor <ConfigurationService>("databaseRoot").Use(userDatabasesPath)
                                  .ForCtor <ConfigurationService>("conf").Use(conf)
                                  .ForCtor <ConfigurationService>("coreRepo").Use(coreRepo)
                                  .For <ILogger>().Use(Log.Default)
                                  .For <IRepository>().Use(coreRepo)
                                  .For <DaoRepository>().Use(coreRepo)
                                  .For <ApplicationRegistrationRepository>().Use(coreRepo)
                                  .For <AppConf>().Use(conf)
                                  .For <IDatabaseProvider>().Use(dbProvider)
                                  .For <IUserManager>().Use(userMgr)
                                  .For <UserManager>().Use(userMgr)
                                  .For <IUserResolver>().Use(userResolver)
                                  .For <DaoUserResolver>().Use(userResolver)
                                  .For <IRoleResolver>().Use(roleResolver)
                                  .For <DaoRoleResolver>().Use(roleResolver)
                                  .For <IRoleProvider>().Use(coreRoleService)
                                  .For <RoleService>().Use(coreRoleService)
                                  .For <EmailComposer>().Use(userMgr.EmailComposer)
                                  .For <IApplicationNameProvider>().Use <ApplicationRegistrationService>()
                                  .For <ApplicationRegistrationService>().Use <ApplicationRegistrationService>()
                                  .For <IApiKeyResolver>().Use <ApplicationRegistrationService>()
                                  .For <ISmtpSettingsProvider>().Use(userMgr)
                                  .For <UserRegistryService>().Use <UserRegistryService>()
                                  .For <ConfigurationService>().Use(configSvc)
                                  .For <IStorableTypesProvider>().Use <NamespaceRepositoryStorableTypesProvider>()
                                  .For <FileService>().Use <FileService>()
                                  .For <IFileService>().Use <FileService>()
                                  .For <AssemblyServiceRepository>().Use(assSvcRepo)
                                  .For <IAssemblyService>().Use <AssemblyService>()
                                  .For <ServiceRegistryRepository>().Use(serviceRegistryRepo)
                                  .For <ServiceRegistryService>().Use <ServiceRegistryService>()
                                  .For <OAuthService>().Use <OAuthService>()
                                  .For <ILog>().Use(loggerSvc)
                                  .For <SystemLoggerService>().Use(loggerSvc)
                                  .For <DataSettings>().Use(DataSettings.Current)
                                  .For <IApplicationNameResolver>().Use <ClientApplicationNameResolver>()
                                  .For <ClientApplicationNameResolver>().Use <ClientApplicationNameResolver>()
                                  .For <SmtpSettingsProvider>().Use(DataSettingsSmtpSettingsProvider.Default)
                                  .For <NotificationService>().Use <NotificationService>()
                                  .For <ILogReader>().Use <SystemLogReaderService>()
                                  .For <CredentialManagementService>().Use <CredentialManagementService>();

            reg.For <ServiceRegistry>().Use(reg)
            .For <DiagnosticService>().Use <DiagnosticService>();

            reg.SetProperties(userMgr);
            userMgr.ServiceProvider = reg;

            reg.For <CompositeRepository>().Use(() =>
            {
                compositeRepo.AddTypes(reg.Get <IStorableTypesProvider>().GetTypes());
                return(compositeRepo);
            });

            ServiceProxySystem.UserResolvers.Clear();
            ServiceProxySystem.RoleResolvers.Clear();
            ServiceProxySystem.UserResolvers.AddResolver(userResolver);
            ServiceProxySystem.RoleResolvers.AddResolver(roleResolver);
            reg.Name = RegistryName;
            return(reg);
        }