using Demo.AsyncProvider; using Demo.Commands; using Demo.DynamicQueries; using Demo.Queries; using FluentValidation; using FluentValidation.AspNetCore; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using PoweredSoft.CQRS; using PoweredSoft.CQRS.Abstractions; using PoweredSoft.CQRS.AspNetCore.Mvc; using PoweredSoft.CQRS.DynamicQuery; using PoweredSoft.CQRS.DynamicQuery.Abstractions; using PoweredSoft.CQRS.DynamicQuery.AspNetCore; using PoweredSoft.CQRS.GraphQL.FluentValidation; using PoweredSoft.CQRS.GraphQL.HotChocolate; using PoweredSoft.Data; using PoweredSoft.Data.Core; using PoweredSoft.DynamicQuery; using System.Linq; using PoweredSoft.CQRS.GraphQL.HotChocolate.DynamicQuery; using PoweredSoft.CQRS.Abstractions.Security; using Demo.Security; using PoweredSoft.CQRS.FluentValidation; using Microsoft.AspNetCore.OData; namespace Demo { public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { AddQueries(services); AddDynamicQueries(services); AddCommands(services); services.AddHttpContextAccessor(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddPoweredSoftDataServices(); services.AddPoweredSoftDynamicQuery(); services.AddPoweredSoftCQRS(); services .AddControllers() .AddPoweredSoftQueries() .AddPoweredSoftCommands() .AddPoweredSoftDynamicQueries() .AddFluentValidation(); services .AddGraphQLServer() .AddProjections() .AddQueryType(d => d.Name("Query")) .AddPoweredSoftQueries() .AddPoweredSoftDynamicQueries() .AddMutationType(d => d.Name("Mutation")) .AddPoweredSoftMutations(); services.AddPoweredSoftGraphQLFluentValidation(); services.AddSwaggerGen(); services.AddCors(); } private void AddDynamicQueries(IServiceCollection services) { services.AddTransient, ContactQueryableProvider>(); services.AddDynamicQuery(); services.AddDynamicQueryWithParams(name: "SearchContacts") .AddAlterQueryableWithParams(); services .AddTransient, PersonQueryableProvider>() .AddDynamicQuery(name: "People") .AddDynamicQueryInterceptors(); } private void AddCommands(IServiceCollection services) { services.AddCommand(); services.AddTransient, CreatePersonCommandValidator>(); /* OLD WAY STILL VALID services.AddCommand(); services.AddTransient, EchoCommandValidator>();*/ // new way :) with PoweredSoft.CQRS.FluentValidation package. services.AddCommandWithValidator(); } private void AddQueries(IServiceCollection services) { services.AddQuery, PersonQueryHandler>(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseHttpsRedirection(); app.UseCors(o => o.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod()); app.UseRouting(); app.UseAuthorization(); app.UseSwagger(); // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), // specifying the Swagger JSON endpoint. app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); }); app.UseEndpoints(endpoints => { endpoints.MapControllers(); endpoints.MapGraphQL(); }); } } }