Exemplo n.º 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Loading and initalizing configuration
            var configSection = Configuration.GetSection(nameof(FrontendConfig));

            if (configSection != null)
            {
                services.Configure <FrontendConfig>(configSection);
                FrontendConfig = configSection.Get <FrontendConfig>();
            }
            else
            {
                throw new System.Exception("Missing configuration for Frontend service!");
            }

            // Loading and initializing the resouces repositories
            var repoFactory = new ResourcesRepository.RepositoryFactory(
                FrontendConfig.ResourcesConfig.SubscriptionId,
                FrontendConfig.ResourcesConfig.ResourceGroupName
                );

            if (!FrontendConfig.SecurityConfig.UseMSI)
            {
                repoFactory.ConfigureEnvironment(
                    FrontendConfig.SecurityConfig.ClientId,
                    FrontendConfig.SecurityConfig.ClientSecret,
                    FrontendConfig.SecurityConfig.TenantId);
            }
            else
            {
                repoFactory.ConfigureEnvironment(FrontendConfig.SecurityConfig.TenantId);
            }
            services.AddSingleton <ResourcesRepository.Interfaces.IResourcesRepo>(f => {
                var logFac = f.GetService <Microsoft.Extensions.Logging.ILoggerFactory>();
                return(repoFactory.CreateResourcesRepo(logFac));
            });
            services.AddSingleton <ResourcesRepository.Interfaces.IStorageRepo>(f => {
                var logFac = f.GetService <Microsoft.Extensions.Logging.ILoggerFactory>();
                return(repoFactory.CreateStorageRepo(logFac, false));
            });

            // Add the gRPC ResourcesBackend agent.
            services.AddGrpcClient <GrpcGreeter.GreeterService.GreeterServiceClient>(opt => {
                opt.Address = new System.Uri(FrontendConfig.EndpointsConfig.BackendServiceEndpointUri);
            });
            services.AddGrpcClient <GrpcResourceManagement.ResourcesService.ResourcesServiceClient>(opt => {
                opt.Address = new System.Uri(FrontendConfig.EndpointsConfig.BackendServiceEndpointUri);
            });

            // ASP.NET Specifics
            services.AddControllersWithViews();
        }
Exemplo n.º 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            var configSection = Configuration.GetSection(nameof(BackendConfig));

            if (configSection != null)
            {
                services.Configure <BackendConfig>(configSection);
                BackendConfig = configSection.Get <BackendConfig>();
            }
            else
            {
                throw new System.Exception("Missing configuration for Backend service!");
            }

            // Loading and initializing the resouces repositories
            var repoFactory = new ResourcesRepository.RepositoryFactory(
                BackendConfig.ResourcesConfig.SubscriptionId,
                BackendConfig.ResourcesConfig.ResourceGroupName
                );

            if (!BackendConfig.SecurityConfig.UseMSI)
            {
                repoFactory.ConfigureEnvironment(
                    BackendConfig.SecurityConfig.ClientId,
                    BackendConfig.SecurityConfig.ClientSecret,
                    BackendConfig.SecurityConfig.TenantId);
            }
            else
            {
                repoFactory.ConfigureEnvironment(BackendConfig.SecurityConfig.TenantId);
            }
            services.AddSingleton <ResourcesRepository.Interfaces.IResourcesRepo>(f => {
                var logFac = f.GetService <Microsoft.Extensions.Logging.ILoggerFactory>();
                return(repoFactory.CreateResourcesRepo(logFac));
            });
            services.AddSingleton <ResourcesRepository.Interfaces.IStorageRepo>(f => {
                var logFac = f.GetService <Microsoft.Extensions.Logging.ILoggerFactory>();
                return(repoFactory.CreateStorageRepo(logFac, false));
            });

            // GRPC Stuff
            services.AddGrpc();
        }