コード例 #1
0
        public App()
        {
            InitializeComponent();

            ServiceRegistrationHelper.RegisterServices();

            WebApplicationFactory.SetHttpPort(8888);

            MainPage = new MainPage();
        }
コード例 #2
0
        protected override void Load(ContainerBuilder builder)
        {
            ServiceRegistrationHelper.RegisterDataContextFromAssembly(ThisAssembly, builder);
            ServiceRegistrationHelper.RegisterDataContextFromAssembly(typeof(TaxDataContext).Assembly, builder);

            builder.RegisterType <APTaxDataBuilder>();
            builder.RegisterType <ARTaxDataBuilder>();
            builder.RegisterType <APInvoiceAggregateBuilderFactory>();
            builder.RegisterType <ARInvoiceAggregateBuilderFactory>();
        }
コード例 #3
0
        public App()
        {
            InitializeComponent();

            ServiceRegistrationHelper.RegisterServices();

#if DEBUG
            WebApplicationFactory.EnableDebugFeatures();
#endif
            WebApplicationFactory.SetHttpPort(8888);

            MainPage = new MainPage();
        }
コード例 #4
0
        public void RegisterServicesFromAssembly(Assembly assembly)
        {
            var assemblyName = assembly.GetName();

            if (m_RegisteredAssemblies.Contains(assembly.GetName()))
            {
                m_Logger.LogDebug("Skipping already registered assembly: " + assemblyName);
                return;
            }

            m_ServiceRegistrations.AddRange(ServiceRegistrationHelper.FindFromAssembly <ServiceImplementationAttribute>(assembly, m_Logger));
            m_RegisteredAssemblies.Add(assemblyName);
            m_Assemblies.Add(assembly);
        }
コード例 #5
0
        public void ConfigureServices(IServiceCollection services)
        {
            var srvRegistration = ServiceRegistrationHelper.GetInstance(Configuration, services);

            srvRegistration.AddCaching();
            srvRegistration.AddEfCoreContext();
            srvRegistration.AddMongoContext();
            srvRegistration.AddControllers();
            srvRegistration.AddJWTAuthentication();
            srvRegistration.AddAuthorization();
            srvRegistration.AddCors(_corsPolicy);
            srvRegistration.AddSwaggerGen();
            srvRegistration.AddHealthChecks();
            services.AddAutoMapper(typeof(AdncProfile));
            services.AddScoped <UserContext>();
        }
コード例 #6
0
ファイル: Startup.cs プロジェクト: lzb66855024/Adnc
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddScoped <UserContext>();
            services.AddHttpContextAccessor();
            services.AddMemoryCache();

            _srvRegistration = new ServiceRegistrationHelper(Configuration, services, _env, _serviceInfo);
            _srvRegistration.Configure();
            _srvRegistration.AddControllers();
            _srvRegistration.AddJWTAuthentication();
            _srvRegistration.AddAuthorization <PermissionHandlerLocal>();
            _srvRegistration.AddCors();
            _srvRegistration.AddHealthChecks();
            _srvRegistration.AddEfCoreContext();
            _srvRegistration.AddMongoContext();
            _srvRegistration.AddCaching();
            _srvRegistration.AddSwaggerGen();
        }
コード例 #7
0
ファイル: Startup.cs プロジェクト: shixb/Adnc
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddScoped <UserContext>();
            services.AddAutoMapper(typeof(AdncUsrProfile));
            services.AddHttpContextAccessor();

            _srvRegistration = new ServiceRegistrationHelper(Configuration, services, _env, _serviceInfo);
            _srvRegistration.Configure();
            _srvRegistration.AddControllers();
            _srvRegistration.AddJWTAuthentication();
            _srvRegistration.AddAuthorization();
            _srvRegistration.AddCors();
            _srvRegistration.AddHealthChecks();
            _srvRegistration.AddMqHostedServices();
            _srvRegistration.AddEfCoreContext();
            _srvRegistration.AddMongoContext();
            _srvRegistration.AddCaching();
            _srvRegistration.AddSwaggerGen();
        }
コード例 #8
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddScoped <UserContext>();
            services.AddAutoMapper(typeof(AdncWarehouseProfile));
            services.AddHttpContextAccessor();

            _srvRegistration = new ServiceRegistrationHelper(_cfg, services, _env, _serviceInfo);
            _srvRegistration.Configure();
            _srvRegistration.AddControllers();
            _srvRegistration.AddJWTAuthentication();
            _srvRegistration.AddAuthorization <PermissionHandlerRemote>();
            _srvRegistration.AddCors();
            _srvRegistration.AddHealthChecks();
            _srvRegistration.AddEfCoreContext();
            _srvRegistration.AddMongoContext();
            _srvRegistration.AddCaching();
            _srvRegistration.AddSwaggerGen();
            _srvRegistration.AddAllRpcServices();
            _srvRegistration.AddAllEventBusSubscribers();
        }
コード例 #9
0
ファイル: Startup.cs プロジェクト: vebin/Adnc
        public void ConfigureServices(IServiceCollection services)
        {
            ServiceCollection = services;
            services.AddScoped <UserContext>();
            services.AddAutoMapper(typeof(AdncMaintProfile));
            services.AddHttpContextAccessor();

            _srvRegistration = new ServiceRegistrationHelper(Configuration, services, _env, _serviceInfo);
            _srvRegistration.Configure();
            _srvRegistration.AddControllers();
            _srvRegistration.AddJWTAuthentication();
            _srvRegistration.AddAuthorization <PermissionHandlerRemote>();
            _srvRegistration.AddCors();
            _srvRegistration.AddHealthChecks();
            _srvRegistration.AddEfCoreContext();
            _srvRegistration.AddMongoContext();
            _srvRegistration.AddCaching();
            _srvRegistration.AddSwaggerGen();
            _srvRegistration.AddAllMqServices();
            _srvRegistration.AddAllRpcServices();

            services.AddConsulServices(_srvRegistration.GetConsulConfig());
        }
コード例 #10
0
        public async Task <IOpenModPlugin> TryActivatePluginAsync(Assembly assembly)
        {
            try
            {
                if (m_IsDisposing)
                {
                    throw new ObjectDisposedException(nameof(PluginActivator));
                }

                var pluginMetadata = assembly.GetCustomAttribute <PluginMetadataAttribute>();
                if (pluginMetadata == null)
                {
                    m_Logger.LogError(
                        $"Failed to load plugin from assembly {assembly}: couldn't find any plugin metadata");
                    return(null);
                }

                var pluginTypes = assembly.FindTypes <IOpenModPlugin>(false).ToList();
                if (pluginTypes.Count == 0)
                {
                    m_Logger.LogError(
                        $"Failed to load plugin from assembly {assembly}: couldn't find any IOpenModPlugin implementation");
                    return(null);
                }

                if (pluginTypes.Count > 1)
                {
                    m_Logger.LogError(
                        $"Failed to load plugin from assembly {assembly}: assembly has multiple IOpenModPlugin instances");
                    return(null);
                }

                var            pluginType = pluginTypes.Single();
                IOpenModPlugin pluginInstance;
                try
                {
                    var serviceProvider = m_LifetimeScope.Resolve <IServiceProvider>();
                    var lifetimeScope   = m_LifetimeScope.BeginLifetimeScope(containerBuilder =>
                    {
                        var workingDirectory = PluginHelper.GetWorkingDirectory(m_Runtime, pluginMetadata.Id);

                        var configurationBuilder = new ConfigurationBuilder();
                        if (Directory.Exists(workingDirectory))
                        {
                            configurationBuilder
                            .SetBasePath(workingDirectory)
                            .AddYamlFile("config.yaml", optional: true, reloadOnChange: true);
                        }

                        var configuration = configurationBuilder
                                            .AddEnvironmentVariables(pluginMetadata.Id.Replace(".", "_") + "_")
                                            .Build();

                        containerBuilder.Register(context => configuration)
                        .As <IConfiguration>()
                        .As <IConfigurationRoot>()
                        .SingleInstance()
                        .OwnedByLifetimeScope();

                        containerBuilder.RegisterType(pluginType)
                        .AsSelf()
                        .As <IOpenModComponent>()
                        .As <IOpenModPlugin>()
                        .SingleInstance()
                        .OwnedByLifetimeScope();

                        containerBuilder.RegisterType <ScopedPermissionChecker>()
                        .As <IPermissionChecker>()
                        .InstancePerLifetimeScope()
                        .OwnedByLifetimeScope();

                        containerBuilder.Register(context => m_DataStoreFactory.CreateDataStore(new DataStoreCreationParameters
                        {
                            ComponentId      = pluginMetadata.Id,
                            Prefix           = null,
                            Suffix           = "data",
                            WorkingDirectory = workingDirectory
                        }))
                        .As <IDataStore>()
                        .SingleInstance()
                        .OwnedByLifetimeScope();

                        var stringLocalizer = Directory.Exists(workingDirectory)
                            ? m_StringLocalizerFactory.Create("translations", workingDirectory)
                            : NullStringLocalizer.Instance;

                        containerBuilder.Register(context => stringLocalizer)
                        .As <IStringLocalizer>()
                        .SingleInstance()
                        .OwnedByLifetimeScope();

                        var services =
                            ServiceRegistrationHelper.FindFromAssembly <PluginServiceImplementationAttribute>(assembly,
                                                                                                              m_Logger);

                        var servicesRegistrations = services.OrderBy(d => d.Priority,
                                                                     new PriorityComparer(PriortyComparisonMode.LowestFirst));

                        foreach (var servicesRegistration in servicesRegistrations)
                        {
                            var implementationType = servicesRegistration.ServiceImplementationType;
                            containerBuilder.RegisterType(implementationType)
                            .As(implementationType)
                            .WithLifetime(servicesRegistration.Lifetime)
                            .OwnedByLifetimeScope();

                            foreach (var service in servicesRegistration.ServiceTypes)
                            {
                                containerBuilder.Register(c => c.Resolve(implementationType))
                                .As(service)
                                .WithLifetime(servicesRegistration.Lifetime)
                                .OwnedByLifetimeScope();
                            }
                        }

                        foreach (var type in pluginType.Assembly.FindTypes <IPluginContainerConfigurator>())
                        {
                            var configurator =
                                (IPluginContainerConfigurator)ActivatorUtilities.CreateInstance(serviceProvider, type);
                            configurator.ConfigureContainer(new PluginServiceConfigurationContext(m_LifetimeScope, configuration, containerBuilder));
                        }

                        var configurationEvent = new PluginContainerConfiguringEvent(pluginMetadata, pluginType,
                                                                                     configuration, containerBuilder, workingDirectory);
                        AsyncHelper.RunSync(() => m_EventBus.EmitAsync(m_Runtime, this, configurationEvent));
                    });

                    pluginInstance = (IOpenModPlugin)lifetimeScope.Resolve(pluginType);
                    var pluginActivateEvent = new PluginActivatingEvent(pluginInstance);
                    await m_EventBus.EmitAsync(m_Runtime, this, pluginActivateEvent);

                    if (pluginActivateEvent.IsCancelled)
                    {
                        await lifetimeScope.DisposeAsync();

                        return(null);
                    }
                }
                catch (Exception ex)
                {
                    m_Logger.LogError(ex,
                                      $"Failed to load plugin from type: {pluginType.FullName} in assembly: {assembly.FullName}");
                    return(null);
                }

                try
                {
                    await pluginInstance.LoadAsync();

                    var serviceProvider  = pluginInstance.LifetimeScope.Resolve <IServiceProvider>();
                    var pluginHelpWriter = ActivatorUtilities.CreateInstance <PluginHelpWriter>(serviceProvider);
                    await pluginHelpWriter.WriteHelpFileAsync();
                }
                catch (Exception ex)
                {
                    m_Logger.LogError(ex, $"Failed to load plugin: {pluginInstance.DisplayName} v{pluginInstance.Version}");

                    try
                    {
                        await pluginInstance.LifetimeScope.DisposeAsync();
                    }
                    catch (Exception e)
                    {
                        m_Logger.LogError(e, "Failed to unload plugin: {DisplayName} v{Version}", pluginInstance.DisplayName, pluginInstance.Version);
                    }

                    return(null);
                }

                m_ActivatedPlugins.Add(new WeakReference(pluginInstance));
                return(pluginInstance);
            }
            catch (Exception ex)
            {
                m_Logger.LogError(ex, $"Failed to load plugin from assembly: {assembly.FullName}");
                return(null);
            }
        }
コード例 #11
0
 protected override void SetupOverride()
 {
     LogoFX.Client.Testing.Shared.TestHelper.Setup();
     ServiceRegistrationHelper.RegisterIntegrationObjects();
     ScenarioHelper.Add(new BuilderRegistrationService(), typeof(IBuilderRegistrationService));
 }