Skip to content

Instantly share code, notes, and snippets.

@ArnisL
Created June 6, 2010 13:45
Show Gist options
  • Save ArnisL/427593 to your computer and use it in GitHub Desktop.
Save ArnisL/427593 to your computer and use it in GitHub Desktop.
namespace Web.Bootstrap {
using CommandHandlers;
using Microsoft.Practices.ServiceLocation;
using MvcExtensions;
using Ncqrs;
using Ncqrs.Commanding.ServiceModel;
using Ncqrs.Config.StructureMap;
using Ncqrs.Domain;
using Ncqrs.Domain.Storage;
using Ncqrs.Eventing.ServiceModel.Bus;
using Ncqrs.Eventing.Storage;
using Ncqrs.Eventing.Storage.MongoDB;
using Reporting;
using Reporting.Denormalizers;
public class NcqrsTask:BootstrapperTask {
protected override TaskContinuation ExecuteCore(IServiceLocator serviceLocator) {
var config=new StructureMapConfiguration(x => {
var eventBus=InitializeEventBus();
x.For<IEventBus>().Use(eventBus);
x.For<IEventStore>().Use<MongoDBEventStore>();
x.For<IUnitOfWorkFactory>().Use<UnitOfWorkFactory>();
});
NcqrsEnvironment.Configure(config);
return TaskContinuation.Continue;
}
public static ICommandService InitializeEventStore() {
//Ncqrs.Commanding.CommandExecution.CommandExecutorBase
var bus=ServiceLocator.Current.GetInstance<IEventBus>();
var service=new CommandService();
var eventStore=new MongoDBEventStore();
var repository=new DomainRepository(eventStore, bus);
service.RegisterExecutor(new RegisterNewAffairHandler(repository));
service.RegisterExecutor(new RegisterNewSportHandler(repository));
service.RegisterExecutor(new SignupNewPlayerHandler(repository));
service.RegisterExecutor(new SignupTeamHandler(repository));
service.RegisterExecutor(new CancelAffairHandler(repository));
//go go go!
return service;
}
public static IEventBus InitializeEventBus() {
var a = new Ncqrs.Eventing.ServiceModel.Bus.InProcessEventBus();
var bus=new InProcessEventBus();
var reportingRepository=ServiceLocator.Current.GetInstance<IReportingRepository>();
var slugService=ServiceLocator.Current.GetInstance<IUrlSlugService>();
bus.RegisterHandler(new AffairRegisteredDenormalizer(reportingRepository, slugService)); //whateva
bus.RegisterHandler(new PlayerSignedUpDenormalizer(reportingRepository));
bus.RegisterHandler(new SportRegisteredDenormalizer(reportingRepository));
bus.RegisterHandler(new TeamSignedUpDenormalizer(reportingRepository));
bus.RegisterHandler(new AffairCanceledDenormalizer(reportingRepository));
return bus;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment