NES (.NET Event Sourcing) is a lightweight framework that helps you build domain models when you're doing event sourcing.
If you're looking to take advantage of event sourcing on the .NET platform then you may also be looking to use NServiceBus and NEventStore. NES is an attempt to fill in the gaps between these two frameworks.
The code required to bring NServiceBus and NEventStore together isn't hard to write but it is important and it does have to work a certain way to take full advantage of both frameworks. There's some great resources out there already that help you write this yourself but ideally you'd want to concentrate on developing your domain model's behaviour rather than the infrastructure to glue these two frameworks together.
NES hooks into NServiceBus' and NEventStore's configuration objects and transparently takes care of everything for you. All you have to do is add two extra lines to your application's initialisation code.
The easiest way to install NES is via NuGet (NES, NES.NEventStore, NES.NEventStore.Raven, NES.NServiceBus) or you can download the source and run 'build.bat' from the command line. Once built, the files will be placed in the 'build' folder.
public class EndpointConfig : IConfigureThisEndpoint, AsA_Publisher, IWantCustomInitialization
{
public void Init()
{
NEventStore.Wireup.Init()
.UsingSqlPersistence("EventStore")
.InitializeStorageEngine()
.NES()
.UsingJsonSerialization()
.Build();
NServiceBus.Configure.With()
.Log4Net()
.DefaultBuilder()
.JsonSerializer()
.NES();
}
}
public class EndpointConfig : IConfigureThisEndpoint, AsA_Server, IWantToRunWhenBusStartsAndStops, IWantToRunWhenConfigurationIsComplete
{
public void Init()
{
LogManager.Use<Log4NetFactory>();
}
public void Start()
{
Wireup.Init()
.UsingInMemoryPersistence()
.EnlistInAmbientTransaction()
.NES()
.Build();
}
public void Stop()
{
}
public void Customize(BusConfiguration configuration)
{
configuration.UseSerialization<Json>();
configuration.EnableInstallers();
configuration.UsePersistence<InMemoryPersistence>();
configuration.UseTransport<MsmqTransport>();
configuration.PurgeOnStartup(false);
}
public void Run(Configure config)
{
config.NES();
}
}
If you customize the BusConfiguration in a way, that you are defining which assemblies should be loading like following
configuration.AssembliesToScan(AllAssemblies.Matching("MyNamespace"));
so please ensure, that also all NES assemblies are loaded as well. You will get NullReferenceException if not doing so.
For a more complete example, please open and build NES.Sample.sln in Visual Studio and hit F5. This will start the NES.Sample NServiceBus endpoint as well as the NES.Sample.Web MVC3 website.