Created
February 14, 2018 12:27
-
-
Save cjrpriest/b536bb69630fd8ff60b1e0089b5abae1 to your computer and use it in GitHub Desktop.
Repo for possible bug in AzureFromTheTrenches.Commanding framework
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 AzureFromTheTrenches.Commanding.MicrosoftDependencyInjection; | |
using Microsoft.Extensions.DependencyInjection; | |
namespace CommandingTest | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var serviceCollection = new ServiceCollection(); | |
var dependencyRosolver = serviceCollection.UseCommanding(); | |
var registry = CommandingDependencies.UseCommanding( | |
new CommandingDependencyResolver( | |
(type, instance) => serviceCollection.AddSingleton(type, instance), | |
(type, impl) => serviceCollection.AddTransient(type, impl), | |
type => dependencyRosolver.ServiceProvider.GetService(type) | |
) | |
); | |
dependencyRosolver.ServiceProvider = serviceCollection.BuildServiceProvider(); | |
registry.Register<TestCommandHandler>(); | |
var commandDispatcher = dependencyRosolver.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