Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created October 4, 2017 01:32
Show Gist options
  • Save dcomartin/a258fb7f3f9cec332a9ec713dbd49596 to your computer and use it in GitHub Desktop.
Save dcomartin/a258fb7f3f9cec332a9ec713dbd49596 to your computer and use it in GitHub Desktop.
internal class Program
{
private static void Main(string[] args)
{
var registry = new SubscriberRegistry();
registry.Register<GreetingCommand, GreetingCommandHandler>();
var tinyIoCContainer = new TinyIoCContainer();
tinyIoCContainer.Register<IHandleRequests<GreetingCommand>, GreetingCommandHandler>();
var commandStore =
new MySqlCommandStore(
new MySqlCommandStoreConfiguration("Server=localhost;Uid=root;Pwd=root;Database=BrighterTests",
"commands"));
tinyIoCContainer.Register<IAmACommandStore>(commandStore);
tinyIoCContainer.Register<IAmACommandStoreAsync>(commandStore);
var builder = CommandProcessorBuilder.With()
.Handlers(new HandlerConfiguration(
subscriberRegistry: registry,
handlerFactory: new TinyIocHandlerFactory(tinyIoCContainer)
))
.DefaultPolicy()
.NoTaskQueues()
.RequestContextFactory(new InMemoryRequestContextFactory());
var commandProcessor = builder.Build();
var greetingCommand = new GreetingCommand("Derek");
commandProcessor.Send(greetingCommand);
var retrievedCommand = commandStore.Get<GreetingCommand>(greetingCommand.Id);
Console.WriteLine(string.Format("Command retrieved from store: {0}", JsonConvert.SerializeObject(retrievedCommand)));
Console.ReadLine();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment