Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.