public BaseSpec() { var builder = new BoundedContextModelBuilder(); builder.UseInMemoryBuses(); builder.UseInMemoryEventStore(); builder.Aggregate <FlightReservation>(cfg => { cfg .WithId(c => c.Localizer) .CreatedBy <CreateFlightReservation>() .Executes <CancelFlightReservation>(c => c.Localizer); }); builder.Projection <ReservationViewProjection>(cfg => { cfg .WithState(c => c.LastEventId) .AutoSubscribe(); }); builder.ReadModel <ReservationView, ReservationViewRepository>(cfg => { cfg.RespondsTo <SearchReservationsByFlight>(c => c.Query); }); Model = builder.Build(); CommandBus = Model.Services.GetRequiredService <ICommandBus>(); Host = new Hosting.HostProcess(Model); Host.Start(); }
public static void Run(string[] args) { Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)); var asmFiles = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.dll"); var builder = new BoundedContextModelBuilder(); var color = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine($"Carupano Host"); Console.ForegroundColor = color; Console.WriteLine("Inspecting available assemblies..."); var configTypes = asmFiles.Select(a => Assembly.Load(new AssemblyName(Path.GetFileNameWithoutExtension(a))).GetTypes().SingleOrDefault(c => c.Name == "Startup")).Where(c => c != null); foreach (var config in configTypes) { Console.WriteLine($"\tFound Startup class {config.Name}"); var method = config.GetMethods().SingleOrDefault(c => c.Name == "Configure" && c.GetParameters().Count() == 1 && c.GetParameters().Single().ParameterType == builder.GetType()); var instance = Activator.CreateInstance(config); method.Invoke(instance, new[] { builder }); Console.WriteLine($"\tConfigured {config.Name}"); } if (!configTypes.Any()) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("No Startup class(es) found."); } else { var model = builder.Build(); var mgr = new ProjectionManager(model.Services.GetService <IEventStore>(), model.Services.GetService <IInboundMessageBus>(), model.Projections.Select(c => c.CreateInstance(model.Services))); mgr.Start(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Carupano is running..."); } Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Press any key to exit process."); Console.ReadKey(); }