public virtual void ConfigureServices(IServiceCollection services) { services.AddMvc(x => { x.EnableEndpointRouting = false; }).AddControllersAsServices(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo { Title = "API", Version = "v1" }); }); services.AddDbContext <AppDbContext>(options => { options.UseSqlServer(Configuration.GetConnectionString("AppDatabase")); options.UseLazyLoadingProxies(); }); var builder = new ContainerBuilder(); builder.Populate(services); ConfigureContainer(builder); Container = builder.Build(); DomainEvents.Init(Container.BeginLifetimeScope()); }
public static void Main(string[] args) { IHost build = CreateHostBuilder(args).Build(); DomainEvents.Init(build.Services); build.Run(); }
public void ConfigureServices(IServiceCollection services) { services.AddMvc().AddControllersAsServices(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "Gestão Escolar API", Version = "v1" }); c.DescribeAllEnumsAsStrings(); }); services.AddDbContext <AppDbContext>(options => { options.UseSqlServer(Configuration.GetConnectionString("AppDatabase")); options.UseLazyLoadingProxies(); }); var builder = new ContainerBuilder(); builder.Populate(services); ConfigureContainer(builder); Container = builder.Build(); DomainEvents.Init(Container.BeginLifetimeScope()); }
public void Install(Castle.Windsor.IWindsorContainer container, Castle.MicroKernel.SubSystems.Configuration.IConfigurationStore store) { container.Register(Classes.FromAssemblyNamed("eCommerce") .BasedOn(typeof(Handles <>)) .WithService.FromInterface(typeof(Handles <>)) .Configure(c => c.LifestyleTransient())); container.Register(Classes.FromAssemblyNamed("eCommerce") .BasedOn <IDomainService>() .WithService.DefaultInterfaces() .Configure(c => c.LifestyleTransient())); container.Register(Component.For <Settings>() .Instance(new Settings(Country.Create(new Guid("229074BD-2356-4B5A-8619-CDEBBA71CC21"), "United Kingdom")) ) ); container.Register(Component.For <Handles <CartCreated> >().ImplementedBy <DomainEventHandle <CartCreated> >().LifestyleSingleton()); container.Register(Component.For <Handles <ProductAddedCart> >().ImplementedBy <DomainEventHandle <ProductAddedCart> >().LifestyleSingleton()); container.Register(Component.For <Handles <ProductRemovedCart> >().ImplementedBy <DomainEventHandle <ProductRemovedCart> >().LifestyleSingleton()); container.Register(Component.For <Handles <CountryCreated> >().ImplementedBy <DomainEventHandle <CountryCreated> >().LifestyleSingleton()); container.Register(Component.For <Handles <CreditCardAdded> >().ImplementedBy <DomainEventHandle <CreditCardAdded> >().LifestyleSingleton()); container.Register(Component.For <Handles <CustomerChangedEmail> >().ImplementedBy <DomainEventHandle <CustomerChangedEmail> >().LifestyleSingleton()); container.Register(Component.For <Handles <CustomerCheckedOut> >().ImplementedBy <DomainEventHandle <CustomerCheckedOut> >().LifestyleSingleton()); container.Register(Component.For <Handles <CustomerCreated> >().ImplementedBy <DomainEventHandle <CustomerCreated> >().LifestyleSingleton()); container.Register(Component.For <Handles <ProductCodeCreated> >().ImplementedBy <DomainEventHandle <ProductCodeCreated> >().LifestyleSingleton()); container.Register(Component.For <Handles <ProductCreated> >().ImplementedBy <DomainEventHandle <ProductCreated> >().LifestyleSingleton()); container.Register(Component.For <Handles <CountryTaxCreated> >().ImplementedBy <DomainEventHandle <CountryTaxCreated> >().LifestyleSingleton()); DomainEvents.Init(container); }
/// <summary> /// Registers the type mappings with the Unity container. /// </summary> /// <param name="container">The unity container to configure.</param> /// <remarks> /// There is no need to register concrete types such as controllers or /// API controllers (unless you want to change the defaults), as Unity /// allows resolving a concrete type even if it was not previously /// registered. /// </remarks> public static void RegisterTypes(IUnityContainer container) { // NOTE: To load from web.config uncomment the line below. // Make sure to add a Unity.Configuration to the using statements. // container.LoadConfiguration(); // TODO: Register your type's mappings here. container.RegisterType <IUserContext, UserContext>( new InjectionConstructor("name=UserContext")); container.RegisterType <ISubscriberContext, SubscriberContext>( new InjectionConstructor("name=UserContext")); container.RegisterType <IEventStoreContext, EventStoreContext>( new InjectionConstructor("name=UserContext")); container.RegisterType <IUserRepository, UserRepository>(); container.RegisterType <ISubscriberRepository, SubscriberRepository>(); container.RegisterType <IUserServices, UserServices>(new InjectionConstructor(container.Resolve <IUserRepository>())); container.RegisterType <INewsLetterService, NewsLetterServices>(new InjectionConstructor(container.Resolve <ISubscriberRepository>())); container.RegisterType <IEventStore, EventStore>(new InjectionConstructor(container.Resolve <IEventStoreContext>())); container.RegisterType <IDomainEventListener <UserWasRegistered>, NewsLetterListener>("NewsLetterListener", new PerRequestLifetimeManager()); container.RegisterType <IDomainEventListener <IDomainEvent>, EventStoreListener>("EventStoreListener", new PerRequestLifetimeManager()); DomainEvents.Init(container); }
//This called at the startup public static void Init() { var connectionString = ConfigurationManager.ConnectionStrings["SnackMachineDDDDatabase"].ConnectionString; SessionFactory.Init(connectionString); //initiate a singleton of headoffice at startup //even if the client try to access the instance through the get property HeadOfficeInstance.Instance, //it won't be able to create another instance!!! //HeadOfficeInstance.Init(); DomainEvents.Init(); }
public void NewCustomerPersists() { Initer.Init(@"Server=(local);Database=test;Trusted_Connection=Yes;"); // comment here DomainEvents.Init(); CustomerRepository customerRepository = new CustomerRepository(); Customer c = new Customer("Pietro"); c.AddCustomerAddedEvent(); Customer d = new Customer("Paolo"); customerRepository.Save(d); }
public void Take_money_raise_an_event() { SessionFactory.Init(@"Server=.;Database=SnackMachineDDD;Trusted_Connection=True;"); DomainEvents.Init(); Atm atm = new Atm(); atm.LoadMoney(OneDollar); //BalanceChangedEvent balanceChangedEvent = null; //DomainEvents.Register<BalanceChangedEvent>(ev => balanceChangedEvent = ev); atm.TakeMoney(1m); //Check event var balanceChangedEvent = atm.DomainEvents[0] as BalanceChangedEvent; //balanceChangedEvent.Should().NotBeNull(); //balanceChangedEvent.Delta.Should().Be(1.01m); atm.ShouldContainsBalanceChangedEvent(1.01m); }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IServiceProvider serviceProvider) { loggerFactory.AddNLog(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler(appBuilder => { appBuilder.Run(async context => { var exceptionHandlerFeature = context.Features.Get <IExceptionHandlerFeature>(); if (exceptionHandlerFeature != null) { var logger = loggerFactory.CreateLogger("Global Exception Logger"); logger.LogError(500, exceptionHandlerFeature.Error, exceptionHandlerFeature.Error.Message); } context.Response.StatusCode = 500; await context.Response.WriteAsync("An unexpected fault happened. Try again later."); }); }); } app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "UMS API V1"); }); AutoMapperConfig.Initialize(); app.UseMvc(); DomainEvents.Init(serviceProvider); }
public void ConfigureServices(IServiceCollection services) { services.AddMvc(x => { x.EnableEndpointRouting = false; }).AddControllersAsServices(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo { Title = "API", Version = "v1" }); }); services.AddDbContext <AppDbContext>(options => { options.UseSqlServer(new SqlConnectionStringBuilder { DataSource = @"(LocalDB)\MSSQLLocalDB", InitialCatalog = DBNameTestIntegration, IntegratedSecurity = true }.ConnectionString); options.UseLazyLoadingProxies(); options.ConfigureWarnings(x => x.Ignore(InMemoryEventId.TransactionIgnoredWarning)); }); var builder = new ContainerBuilder(); builder.Populate(services); ConfigureContainer(builder); Container = builder.Build(); DomainEvents.Init(Container.BeginLifetimeScope()); new AutofacServiceProvider(Container.BeginLifetimeScope()); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider serviceProvider) { //ServiceProvider = serviceProvider; app.UseResponseCompression(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseCors( builder => builder.AllowAnyOrigin() .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials()) .UseStaticFiles() .UseWebSockets(); app.Use(async(context, next) => { await next(); if (context.Response.StatusCode == 404 && !Path.HasExtension(context.Request.Path.Value) && !context.Request.Path.Value.StartsWith("/api/")) { context.Request.Path = "/index.html"; await next(); } }); app.UseMvcWithDefaultRoute(); app.UseDefaultFiles(); app.UseStaticFiles() .UseSwaggerUi(); var hfServerOptions = new BackgroundJobServerOptions() { ServerName = $"dwapi", WorkerCount = Environment.ProcessorCount * 5, Queues = new string[] { "mpi", "default" } }; app.UseHangfireDashboard(); app.UseHangfireServer(hfServerOptions); GlobalJobFilters.Filters.Add(new AutomaticRetryAttribute() { Attempts = 3 }); Log.Debug(@"initializing Database..."); EnsureMigrationOfContext <SettingsContext>(serviceProvider); EnsureMigrationOfContext <ExtractsContext>(serviceProvider); app.UseSignalR( routes => { routes.MapHub <ExtractActivity>($"/{nameof(ExtractActivity).ToLower()}"); routes.MapHub <CbsActivity>($"/{nameof(CbsActivity).ToLower()}"); routes.MapHub <HtsActivity>($"/{nameof(HtsActivity).ToLower()}"); routes.MapHub <DwhSendActivity>($"/{nameof(DwhSendActivity).ToLower()}"); routes.MapHub <CbsSendActivity>($"/{nameof(CbsSendActivity).ToLower()}"); routes.MapHub <HtsSendActivity>($"/{nameof(HtsSendActivity).ToLower()}"); } ); Mapper.Initialize(cfg => { cfg.AddDataReaderMapping(); cfg.AddProfile <TempExtractProfile>(); cfg.AddProfile <TempMasterPatientIndexProfile>(); cfg.AddProfile <EmrProfiles>(); cfg.AddProfile <TempHtsExtractProfile>(); } ); DomainEvents.Init(); try { DapperPlusManager.AddLicense("1755;700-ThePalladiumGroup", "2073303b-0cfc-fbb9-d45f-1723bb282a3c"); if (!Z.Dapper.Plus.DapperPlusManager.ValidateLicense(out var licenseErrorMessage)) { throw new Exception(licenseErrorMessage); } } catch (Exception e) { Log.Debug($"{e}"); throw; } Log.Debug(@"initializing Database [Complete]"); Log.Debug( @"---------------------------------------------------------------------------------------------------"); Log.Debug (@" _____ _ | __ \ (_) | | | |_ ____ _ _ __ _ | | | \ \ /\ / / _` | '_ \| | | |__| |\ V V / (_| | |_) | | |_____/ \_/\_/ \__,_| .__/|_| | | |_| "); Log.Debug( @"---------------------------------------------------------------------------------------------------"); Log.Debug("Dwapi started !"); }
void StartDomainHandlers(IServiceCollection services) { DomainEvents.Init(services); }
public static void Init() { SessionFactory.Init(ConfigurationManager.ConnectionStrings["DDDInPractice"].ConnectionString); HeadOfficeInstance.Init(new HeadOfficeRepository()); DomainEvents.Init(); }
public static void Init() { SessionFactory.Init(@"Server=.;Database=DomainDrivenDesign;Trusted_Connection=true"); DomainEvents.Init(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider serviceProvider) { //ServiceProvider = serviceProvider; if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseCors( builder => builder.AllowAnyOrigin() .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials()) .UseStaticFiles() .UseWebSockets(); app.Use(async(context, next) => { await next(); if (context.Response.StatusCode == 404 && !Path.HasExtension(context.Request.Path.Value) && !context.Request.Path.Value.StartsWith("/api/")) { context.Request.Path = "/index.html"; await next(); } }); app.UseMvcWithDefaultRoute(); app.UseDefaultFiles(); app.UseStaticFiles() .UseSwaggerUi(); Log.Debug(@"initializing Database..."); EnsureMigrationOfContext <SettingsContext>(serviceProvider); EnsureMigrationOfContext <ExtractsContext>(serviceProvider); app.UseSignalR( routes => { routes.MapHub <ExtractActivity>($"/{nameof(ExtractActivity).ToLower()}"); routes.MapHub <CbsActivity>($"/{nameof(CbsActivity).ToLower()}"); routes.MapHub <DwhSendActivity>($"/{nameof(DwhSendActivity).ToLower()}"); routes.MapHub <CbsSendActivity>($"/{nameof(CbsSendActivity).ToLower()}"); } ); Mapper.Initialize(cfg => { cfg.AddDataReaderMapping(); cfg.AddProfile <TempExtractProfile>(); cfg.AddProfile <TempMasterPatientIndexProfile>(); } ); DomainEvents.Init(); try { DapperPlusManager.AddLicense("1755;701-ThePalladiumGroup", "9005d618-3965-8877-97a5-7a27cbb21c8f"); if (!Z.Dapper.Plus.DapperPlusManager.ValidateLicense(out var licenseErrorMessage)) { throw new Exception(licenseErrorMessage); } } catch (Exception e) { Log.Debug($"{e}"); throw; } Log.Debug(@"initializing Database [Complete]"); Log.Debug( @"---------------------------------------------------------------------------------------------------"); Log.Debug (@" _____ _ | __ \ (_) | | | |_ ____ _ _ __ _ | | | \ \ /\ / / _` | '_ \| | | |__| |\ V V / (_| | |_) | | |_____/ \_/\_/ \__,_| .__/|_| | | |_| "); Log.Debug( @"---------------------------------------------------------------------------------------------------"); Log.Debug("Dwapi started !"); }
public static void Init(string connectionString) { SessionFactory.Init(connectionString); HeadOfficeInstance.Init(); DomainEvents.Init(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider serviceProvider) { Stopwatch stopWatch = Stopwatch.StartNew(); //ServiceProvider = serviceProvider; app.UseResponseCompression(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseCors( builder => builder .WithOrigins("http://*****:*****@"initializing Database..."); EnsureMigrationOfContext <SettingsContext>(serviceProvider); EnsureMigrationOfContext <ExtractsContext>(serviceProvider); app.UseSignalR( routes => { routes.MapHub <ExtractActivity>($"/{nameof(ExtractActivity).ToLower()}"); routes.MapHub <CbsActivity>($"/{nameof(CbsActivity).ToLower()}"); routes.MapHub <HtsActivity>($"/{nameof(HtsActivity).ToLower()}"); routes.MapHub <MgsActivity>($"/{nameof(MgsActivity).ToLower()}"); routes.MapHub <DwhSendActivity>($"/{nameof(DwhSendActivity).ToLower()}"); routes.MapHub <CbsSendActivity>($"/{nameof(CbsSendActivity).ToLower()}"); routes.MapHub <HtsSendActivity>($"/{nameof(HtsSendActivity).ToLower()}"); routes.MapHub <MgsSendActivity>($"/{nameof(MgsSendActivity).ToLower()}"); } ); Mapper.Initialize(cfg => { cfg.AddDataReaderMapping(); cfg.AddProfile <TempExtractProfile>(); cfg.AddProfile <TempMasterPatientIndexProfile>(); cfg.AddProfile <EmrProfiles>(); cfg.AddProfile <TempHtsExtractProfile>(); if (null != AppFeature && AppFeature.PKV.IsValid) { cfg.AddProfile <MasterPatientIndexProfileResearch>(); } else { cfg.AddProfile <MasterPatientIndexProfile>(); } cfg.AddProfile <TempMetricExtractProfile>(); } ); DomainEvents.Init(); stopWatch.Stop(); Log.Debug(@"initializing Database [Complete]"); if (null != AppFeature) { Log.Debug(new string('=', 50)); Log.Debug("Features"); Log.Debug($" {AppFeature.PKV}"); Log.Debug(new string('=', 50)); } Log.Debug( @"---------------------------------------------------------------------------------------------------"); Log.Debug (@" _____ _ | __ \ (_) | | | |_ ____ _ _ __ _ | | | \ \ /\ / / _` | '_ \| | | |__| |\ V V / (_| | |_) | | |_____/ \_/\_/ \__,_| .__/|_| | | |_| "); Log.Debug( @"---------------------------------------------------------------------------------------------------"); if (StartupErrors.Any()) { Log.Error(new string('*', 60)); Log.Error($"Dwapi startup FAILED, took {stopWatch.ElapsedMilliseconds} ms"); Log.Error($"Startup Failed Due to the follwing {StartupErrors.Count} ERROR(s)"); Log.Error(new string('-', 60)); StartupErrors.ForEach(Log.Error); Log.Error(new string('-', 60)); Log.Error(new string('*', 60)); } else { Log.Debug($"Dwapi started in {stopWatch.ElapsedMilliseconds} ms"); } }
public static void Initialize() { DomainEvents.Init(); }