public static IServiceCollection AddApplication(this IServiceCollection serviceCollection, ICommandRegistry commandRegistry) { serviceCollection .AddTransient <IPostRepository, PostRepository>() ; commandRegistry.Discover(typeof(SubsystemRegistration).Assembly); return(serviceCollection); }
public static IServiceCollection AddProductApplication(this IServiceCollection serviceCollection, ICommandRegistry commandRegistry) { // Register validators serviceCollection.AddTransient <IValidator <GetProductQuery>, GetProductQueryValidator>(); // Register commands with discovery approach commandRegistry.Discover(typeof(IServiceCollectionExtensions).Assembly); return(serviceCollection); }
public static IServiceCollection AddApplication(this IServiceCollection serviceCollection, ICommandRegistry commandRegistry) { serviceCollection .AddSingleton <IPostRepository, PostRepository>() .AddTransient <IValidator <AddPostCommand>, AddPostCommandValidator>() .AddTransient <IValidator <GetPostQuery>, GetPostQueryValidator>(); commandRegistry.Discover(typeof(SubsystemRegistration).Assembly); return(serviceCollection); }
public static IServiceCollection AddNotificationApplication(this IServiceCollection serviceCollection, ICommandRegistry commandRegistry) { // Register helpers serviceCollection.AddTransient <IEmail, Email>(); // Register validators serviceCollection.AddTransient <IValidator <SendEmailCommand>, SendEmailCommandValidator>(); // Register commands with discovery approach commandRegistry.Discover(typeof(IServiceCollectionExtensions).Assembly); return(serviceCollection); }
public static IServiceCollection AddApplication(this IServiceCollection services, ICommandRegistry commandRegistry) { services .AddAutoMapper(typeof(SubsystemRegistration)) .AddTransient <IJwtHelper, JwtHelper>() .AddValidators() .AddRepositories(); commandRegistry.Discover(typeof(SubsystemRegistration).Assembly); return(services); }
public static IServiceCollection AddApplication(this IServiceCollection serviceCollection, ICommandRegistry commandRegistry) { // Repositories serviceCollection.AddSingleton(PostRepository.Get()); serviceCollection.AddSingleton(AuthorRepository.Get()); // Validators serviceCollection.AddTransient <IValidator <CreatePostCommand>, CreatePostCommandValidator>(); // Command Handlers commandRegistry.Discover(typeof(IServiceCollectionExtensions).Assembly); return(serviceCollection); }
public static void UseTodoServices(this IServiceCollection services, ICommandRegistry commandRegistry) { if (services == null || commandRegistry == null) { throw new Exception("Both services and the command registry are required"); } commandRegistry.Discover(typeof(Bootstrapper).Assembly); services.AddTransient <IValidator <CreateTodoRequest>, CreateTodoRequestValidator>(); services.AddTransient <IValidator <GetTasksRequest>, GetTasksRequestValidator>(); services.AddScoped <IMapper <CreateTodoRequest, Domain.Models.Todo>, CreateTodoRequestToTodoMapper>(); services.AddScoped <IMapper <Domain.Models.Todo, DisplayTodo>, TodoToDisplayTodoMapper>(); }
// 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) { CommandingDependencyResolverAdapter adapter = new CommandingDependencyResolverAdapter( (fromType, toInstance) => services.AddSingleton(fromType, toInstance), (fromType, toType) => services.AddTransient(fromType, toType), resolveType => _serviceProvider.GetService(resolveType) ); ICommandRegistry registry = adapter.AddCommanding(); registry.Discover <Startup>(); services.AddControllers(); services.AddAuthentication(x => { x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(x => { x.RequireHttpsMetadata = false; x.SaveToken = true; x.TokenValidationParameters = new TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(null), ValidateIssuer = false, ValidateAudience = false }; }); /*services.AddSwaggerGen(c => * { * c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" }); * });*/ }
// This method gets called by the runtime. Use this method to add services to the container. public virtual void ConfigureServices(IServiceCollection services) { string storageAccountConnectionString = Configuration["storage:connectionstring"]; string expensiveOperationQueueName = Configuration["storage:queuename"]; CommandingDependencyResolverAdapter resolver = new CommandingDependencyResolverAdapter( (fromType, toInstance) => services.AddSingleton(fromType, toInstance), (fromType, toType) => services.AddTransient(fromType, toType), (resolveTo) => _serviceProvider.GetService(resolveTo)); // Using an instance of CommandingRuntime rather than the static helpers isolates // this commanding infrastructure to this startup class / instance of the web app // which means that acceptance tests can be run in parallel with multiple instances // of the ASP.Net Core test server. ICommandRegistry registry = _commandingRuntime.AddCommanding(resolver); //ICommandRegistry registry = resolver.AddCommanding(); resolver.AddQueues().AddAzureStorageCommanding(); // Register our command handlers using the discovery approach. Our handlers are in this assembly // so we just pass through our assembly registry.Discover(typeof(Startup).Assembly); // Register our expensive operation command to be sent to a queue registry.Register <ExpensiveOperationCommand>( CloudQueueDispatcherFactory.Create(storageAccountConnectionString, expensiveOperationQueueName)); // Register our commands as REST endpoints. This results in an API where the AddCommand, GetPostsQuery, // GetPostsForCurrentUserQuery and GetPostQuery are handled as GET requests and executed immediately // in process by the registered handlers while the ExpensiveOperationCommand is exposed as a POST operation // and results in the command being placed on a queue services .AddMvc(ConfigureMvcOptions) // this block configures our commands to be exposed on endpoints .AddAspNetCoreCommanding(cfg => cfg .Controller("Post", controller => controller .Action <GetPostsQuery>(HttpMethod.Get) .Action <GetPostQuery, FromRouteAttribute>(HttpMethod.Get, "{PostId}") .Action <AddNewPostCommand>(HttpMethod.Post) .Action <DeletePostCommand>(HttpMethod.Delete, "{PostId}") ) .Controller("Profile", controller => controller .Action <GetPostsForCurrentUserQuery>(HttpMethod.Get, "Posts")) .Controller("ExpensiveOperation", controller => controller .Action <ExpensiveOperationCommand>(HttpMethod.Post)) .Controller("SecurityTest", controller => controller .Action <SecurityTestCommand>(HttpMethod.Post) // we wire this one up with an ActionDefinition model to cover that test path .Action(new ActionDefinition { BindingAttributeType = typeof(FromQueryAttribute), CommandType = typeof(SecurityTestCommand), ResultType = null, Route = "asQueryParam", Verb = HttpMethod.Get })) .Claims(ConfigureClaimsMapping) .LogControllerCode(code => { // this will output the code that is compiled for each controller to the debug window Debug.WriteLine(code); }) ); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "Acceptance Test API", Version = "v1" }); c.AddAspNetCoreCommanding(); }); }