public AdoProjectHistoryController(ILogger <AdoProjectHistoryController> logger, IAdoProjectHistoryRepository repository, IMapper mapper) { _logger = logger; _repository = repository; _mapper = mapper; }
public CreateApprovedAdoProjectIdsCommandHandler ( IProjectAdoServices projectAdoServices, IAdoProjectRepository adoProjectRepository, IAdoProjectHistoryRepository adoProjectHistoryRepository, IMapper mapper, ILogger <CreateApprovedAdoProjectIdsCommandHandler> logger ) { _projectAdoServices = projectAdoServices; _adoProjectRepository = adoProjectRepository; _adoProjectHistoryRepository = adoProjectHistoryRepository; _mapper = mapper; _logger = logger; }
public GenerateEmailForApprovalService( IEmailService emailService, IAdoProjectHistoryRepository adoProjectHistoryRepository, IAdoProjectApproverService adoProjectApproverService, ILogger <GenerateEmailForApprovalService> logger ) { _emailService = emailService; _adoProjectHistoryRepository = adoProjectHistoryRepository; _adoProjectApproverService = adoProjectApproverService; _logger = logger; //TODO Config value _sender = "*****@*****.**"; }
public AzServiceBusConsumer( IConfiguration configuration, IMessageBus messageBus, IMediator mediator, IProjectAdoServices projectAdoServices, IAdoProjectRepository adoProjectRepository, IAdoProjectHistoryRepository adoProjectHistoryRepository, IMapper mapper, ILogger <AzServiceBusConsumer> logger) { _configuration = configuration; _messageBus = messageBus; _mediator = mediator; _projectAdoServices = projectAdoServices; _adoProjectRepository = adoProjectRepository; _adoProjectHistoryRepository = adoProjectHistoryRepository; _logger = logger; }
public AdoProjectRepository( IConfiguration configuration, IRepository <AdoProject> repository, AdoContext context, IAdoProjectHistoryRepository adoProjectHistoryRepository, IPropertyMappingService propertyMappingService, IMapper mapper, ILogger <AdoProjectRepository> logger, IMessageBus messageBus, IApiIdentity apiIdentity) : base(context, apiIdentity) { _repository = repository; _context = context; _adoProjectHistoryRepository = adoProjectHistoryRepository; _propertyMappingService = propertyMappingService; _mapper = mapper; _logger = logger; _messageBus = messageBus; _userId = ApiIdentity.GetUserName(); _serviceBusConfig = configuration.GetSection(nameof(ServiceBusConfig)).Get <ServiceBusConfig>(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); services.AddMediatR(Assembly.GetExecutingAssembly()); services.AddApplicationServices(Configuration, _env, _logger); string ApiEndpointAuth = Configuration.GetValue <string>(ConstatCsro.EndPoints.ApiEndpointAuth); services.AddHttpClient(Core.ConstatCsro.EndPoints.ApiEndpointAuth, (client) => { client.Timeout = TimeSpan.FromMinutes(ConstatCsro.ClientNames.API_TimeOut_Mins); client.BaseAddress = new Uri(ApiEndpointAuth); client.DefaultRequestHeaders.Add("Accept", "application/json"); }).ConfigurePrimaryHttpMessageHandler(() => { return(new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip | DecompressionMethods.Brotli, UseCookies = false }); }) .SetHandlerLifetime(TimeSpan.FromMinutes(5)) .AddPolicyHandler(PollyHelper.GetRetryPolicy()) .AddPolicyHandler(PollyHelper.GetRetryPolicy()); ; #region Auth services.AddAuthorization(options => { // By default, all incoming requests will be authorized according to the default policy //Will automatical sign in user //options.FallbackPolicy = options.DefaultPolicy; options.AddPolicy(PoliciesCsro.CanApproveAdoRequestPolicy, policy => policy.RequireClaim(ClaimTypesCsro.CanApproveAdoRequestClaim, true.ToString())); }); //TODO replace with rest or GRPC service services.AddScoped <IRestUserService, RestUserService>(); services.AddScoped <IClaimsTransformation, ClaimsTransformation>(); #endregion services.AddApplicationInsightsTelemetry(); services.AddControllers(); services.AddMvc(options => { options.Filters.Add(new CsroValidationFilter()); }) .AddFluentValidation(options => { //options.RegisterValidatorsFromAssemblyContaining<Startup>(); options.RegisterValidatorsFromAssemblyContaining <Validation.BaseAdoAbstractValidator>(); }); services.AddScoped <IApiIdentity, ApiIdentity>(); services.AddScoped <IEmailService, EmailService>(); services.AddSingleton <IMessageBus, AzServiceBusMessageBus>(); services.AddTransient <IProjectAdoServices, ProjectAdoServices>(); services.AddTransient <IProcessAdoServices, ProcessAdoServices>(); services.AddSingleton <ICacheProvider, CacheProvider>(); //testing services.AddTransient <IPropertyMappingService, AdoPropertyMappingService>(); //services.AddSingleton<IServiceBusConsumer, AzServiceBusConsumer>(); services.AddScoped <IAdoProjectApproverService, AdoProjectApproverService>(); services.AddScoped <IGenerateEmailForApprovalService, GenerateEmailForApprovalService>(); services.AddScoped <IAdoProjectAccessRepository, AdoProjectAccessRepository>(); //services.AddControllers(options => options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute())); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = _namespace, Version = "v1" }); }); #region DbContext DbTypeEnum DbTypeEnum = DbTypeEnum.Unknown; try { DbTypeEnum = Configuration.GetValue <DbTypeEnum>(nameof(DbTypeEnum)); } catch { } services.AddDbContext <AdoContext>(options => { if (DbTypeEnum == DbTypeEnum.SqlLite) { options.UseSqlite(Configuration.GetConnectionString(KeyVaultConfig.ConnectionStrings.AdoDb), x => x.MigrationsAssembly(_namespace)); } else if (DbTypeEnum == DbTypeEnum.InMemory) { options.UseInMemoryDatabase(databaseName: KeyVaultConfig.ConnectionStrings.AdoDb); } else { options.UseSqlServer(Configuration.GetConnectionString(KeyVaultConfig.ConnectionStrings.AdoDb), x => x.MigrationsAssembly(_namespace)); } }); //services.AddDbContext<TokenCacheContext>(options => //{ // if (UseSqlLiteDb) // options.UseSqlite(Configuration.GetConnectionString(KeyVaultConfig.ConnectionStrings.TokenCacheDb)); // else // options.UseSqlServer(Configuration.GetConnectionString(KeyVaultConfig.ConnectionStrings.TokenCacheDb)); //}); #endregion #region Repositories services.AddScoped(typeof(IRepository <>), typeof(AdoRepository <>)); services.AddScoped <IAdoProjectHistoryRepository, AdoProjectHistoryRepository>(); services.AddScoped <IAdoProjectRepository, AdoProjectRepository>(); #endregion var busConfig = Configuration.GetSection(nameof(BusConfig)).Get <BusConfig>(); if (busConfig == null) { _logger.LogWarning($"No {nameof(BusConfig)} found."); } else { _logger.LogInformation($"{nameof(BusConfig)} is {busConfig} ", busConfig); //_logger.LogInformation("BusConfig is {busConfig} ", busConfig); if (busConfig.IsBusEnabled && busConfig.BusTypeEnum == BusTypeEnum.AzureServiceBus) { //should be last to hav all dependencies services.AddHostedService <ProjectApprovalHostedService>(sp => { var serviceProvider = services.BuildServiceProvider(); var apiIdentity = serviceProvider.GetService <IApiIdentity>(); var ctx = serviceProvider.GetService <AdoContext>(); IRepository <AdoProject> obj = new Repository <AdoProject>(ctx, apiIdentity); var logger = sp.GetService <ILogger <ProjectApprovalHostedService> >(); IGenerateEmailForApprovalService generateEmailForApprovalService = serviceProvider.GetService <IGenerateEmailForApprovalService>(); return(new ProjectApprovalHostedService(generateEmailForApprovalService, logger)); }); services.AddHostedService <AzServiceBusConsumer>(sp => { var serviceProvider = services.BuildServiceProvider(); //var serviceProvider = sp; var apiIdentity = serviceProvider.GetService <IApiIdentity>(); var ctx = serviceProvider.GetService <AdoContext>(); IRepository <AdoProject> obj = new Repository <AdoProject>(ctx, apiIdentity); IConfiguration configuration = serviceProvider.GetService <IConfiguration>(); IMessageBus messageBus = serviceProvider.GetService <IMessageBus>(); IMediator mediator = serviceProvider.GetService <IMediator>(); IProjectAdoServices projectAdoServices = serviceProvider.GetService <IProjectAdoServices>(); IAdoProjectRepository adoProjectRepository = serviceProvider.GetService <IAdoProjectRepository>(); IAdoProjectHistoryRepository adoProjectHistoryRepository = serviceProvider.GetService <IAdoProjectHistoryRepository>(); IMapper mapper = serviceProvider.GetService <IMapper>(); ILogger <AzServiceBusConsumer> logger = serviceProvider.GetService <ILogger <AzServiceBusConsumer> >(); return(new AzServiceBusConsumer(configuration, messageBus, mediator, projectAdoServices, adoProjectRepository, adoProjectHistoryRepository, mapper, logger)); }); } } }