Created
February 14, 2018 13:36
-
-
Save JamesRandall/87c31114ebde542f82cbb9c2fe2ae7c6 to your computer and use it in GitHub Desktop.
Reworked code as part of fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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