Skip to content

Instantly share code, notes, and snippets.

@JamesRandall
Created February 14, 2018 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamesRandall/87c31114ebde542f82cbb9c2fe2ae7c6 to your computer and use it in GitHub Desktop.
Save JamesRandall/87c31114ebde542f82cbb9c2fe2ae7c6 to your computer and use it in GitHub Desktop.
Reworked code as part of fix
/*
Nuget packages included:
- AzureFromTheTrenches.Commanding 6.1.0
- AzureFromTheTrenches.Commanding.MicrosoftDependencyInjection 6.1.0
- Microsoft.Extensions.DependencyInjection 2.0.0
*/
using System;
using System.Threading.Tasks;
using AzureFromTheTrenches.Commanding;
using AzureFromTheTrenches.Commanding.Abstractions;
using Microsoft.Extensions.DependencyInjection;
namespace CommandingTest
{
class Program
{
static void Main(string[] args)
{
IServiceProvider serviceProvider = null;
var serviceCollection = new ServiceCollection();
var registry = CommandingDependencies.UseCommanding(
new CommandingDependencyResolver(
(type, instance) => serviceCollection.AddSingleton(type, instance),
(type, impl) => serviceCollection.AddTransient(type, impl),
type => serviceProvider.GetService(type)
)
);
registry.Register<TestCommandHandler>();
serviceProvider = serviceCollection.BuildServiceProvider();
var commandDispatcher = serviceProvider.GetService<ICommandDispatcher>();
commandDispatcher.DispatchAsync(new TestCommand()).Wait();
}
}
class TestCommand : ICommand
{
public int Param { get; set; }
}
class TestCommandHandler : ICommandHandler<TestCommand>
{
public Task ExecuteAsync(TestCommand command)
{
throw new ApplicationException("This should be thrown!");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment