JamesRandall / AzureFromTheTrenches.Commanding

A configuration based commanding and mediator framework that supports command dispatch and execution in-process, over HTTP or over Azure Storage Queues. Written to .NET Standard 2.0 and supports many popular runtimes including .NET Core and .NET 4.6.x.

Home Page:http://www.azurefromthetrenches.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error executing commandDispatcher.DispatchAsync()

indulismisins opened this issue · comments

Hi,

Gett error when I try to execute method:
await _commandDispatcher.DispatchAsync(getStandardOrganizationQuery);

Error:
System.Private.CoreLib: Exception while executing function: LoadWorkflows. AzureFromTheTrenches.Commanding: Error occurred during command execution. AzureFromTheTrenches.Commanding: A handler of type ImportAsAService.Application.StandardOrganizations.Queries.GetStandardOrganization.GetStandardOrganizationQueryHandler is registered but resolution returned null. Please check IoC configuration.

I have implemented Azure function v3 in NET Core 3.1.

My startup.cs file:

[assembly: FunctionsStartup(typeof(Startup))]

namespace ImportAsAService.Service
{
    internal class Startup : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            var serviceProvider = builder.Services.BuildServiceProvider();
            var adapter = new CommandingDependencyResolverAdapter(
                (fromType, toInstance) => builder.Services.AddSingleton(fromType, toInstance),
                (fromType, toType) => builder.Services.AddTransient(fromType, toType),
                (resolveTo) => serviceProvider.GetService(resolveTo));
            var registry = adapter.AddCommanding();

            registry.Register<GetStandardOrganizationQueryHandler>();

            ... other service registration
        }
    }
}

I don't understand what I'm missing here. Please help me.

Thank you,
Indulis

Hi
Found solution to my problem. Changed CommandingDependencyResolverAdapter constructor:
var adapter = new CommandingDependencyResolverAdapter( (fromType, toInstance) => builder.Services.AddSingleton(fromType, toInstance), (fromType, toType) => builder.Services.AddTransient(fromType, toType), (resolveTo) => builder.Services.BuildServiceProvider().GetService(resolveTo)); var registry = adapter.AddCommanding();