Giter Club home page Giter Club logo

jamesrandall / azurefromthetrenches.commanding Goto Github PK

View Code? Open in Web Editor NEW
45.0 6.0 10.0 3.44 MB

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

License: MIT License

C# 65.52% PowerShell 0.43% HTML 0.22% JavaScript 17.78% Liquid 0.91% CSS 15.13%
dispatch dispatch-commands asp mediator command netstandard20

azurefromthetrenches.commanding's People

Contributors

cjrpriest avatar jamesrandall avatar yodasmydad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

azurefromthetrenches.commanding's Issues

Request: Make CommandRegistry.RegisterHandler public

More of a request than an issue.

There is some code I'm experimenting with in FunctionMonkey, but the roadblock Im running into is in: AzureFromTheTrenches.Commanding.Implementation.CommandRegistry
The RegisterHandler method is private and the Register methods that calls it assume .Single in some places that I want multiple (one class handling a generic cookie cutter abstraction of different handlers for REST). The easiest solution (and I have tested with reflection) would be to expose the RegisterHandler method publically in the interface. Thoughts?

Awesome library BTW. Im having more fun with FunctionMonkey(and by proxy this commanding lib) than I have in a long time.

GettingStartedSample compilation error

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
1> at FunctionMonkey.Compiler.HandlebarsHelpers.HttpVerbsHelper.HelperFunction(TextWriter writer, Object context, Boolean toLowerCase, Object[] parameters) in C:\wip\myOpenSource\functionMonkey\Source\FunctionMonkey.Compiler\HandlebarsHelpers\HttpVerbsHelper.cs:line 28
1> at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid5[T0,T1,T2,T3,T4](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
1> at FunctionMonkey.Compiler.HandlebarsHelpers.HttpVerbsHelper.<>c.b__0_1(TextWriter writer, Object context, Object[] parameters) in C:\wip\myOpenSource\functionMonkey\Source\FunctionMonkey.Compiler\HandlebarsHelpers\HttpVerbsHelper.cs:line 15
1> at lambda_method(Closure , TextWriter , Object )
1> at HandlebarsDotNet.Handlebars.HandlebarsEnvironment.<>c__DisplayClass7_0.b__0(Object context)
1> at FunctionMonkey.Compiler.Implementation.JsonCompiler.Compile(IReadOnlyCollection`1 functionDefinitions, OpenApiOutputModel openApiOutputModel, String outputBinaryFolder, String outputNamespaceName) in C:\wip\myOpenSource\functionMonkey\Source\FunctionMonkey.Compiler\Implementation\JsonCompiler.cs:line 34
1> at FunctionMonkey.Compiler.Implementation.FunctionCompiler.Compile() in C:\wip\myOpenSource\functionMonkey\Source\FunctionMonkey.Compiler\Implementation\FunctionCompiler.cs:line 71
1> at FunctionMonkey.Compiler.Program.Main(String[] args) in C:\wip\myOpenSource\functionMonkey\Source\FunctionMonkey.Compiler\Program.cs:line 44

Request: Do no discover abstract CommandHandler classes

Could you please add the condition !x.IsAbstract() in CommandRegistry:

    public ICommandRegistry Discover(params Assembly[] assemblies)
        {
            Type commandHandlerBase = typeof(ICommandHandlerBase);
            foreach (Assembly assembly in assemblies)
            {
                Type[] handlers = assembly.GetTypes().Where(x => !x.IsAbstract() && commandHandlerBase.IsAssignableFrom(x)).ToArray();
                foreach (Type handler in handlers)
                {
                    Register(handler);
                }
            }
            return this;
        }

I'm using some abstract CommandHandler base classes with unspecified generic parameters that will crash FunctionMonkey when registered to the CommandRegistry.

How to use this with multiple projects using the HostingStartup attribute?

Have a look here for info on the new HostingStartup attribute

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/platform-specific-configuration?view=aspnetcore-2.2

In short, I have several projects within a solution that all use this as (to me) it's a great way to add startup code to separate projects. I have a X.Core project where I'd like to setup the framework like below.

        // Add the Commanding Framework
        var adapter = new CommandingDependencyResolverAdapter(
            (fromType, toInstance) => services.AddSingleton(fromType, toInstance),
            (fromType, toType) => services.AddTransient(fromType, toType),
            resolveTo => _serviceProvider.GetService(resolveTo));
        var registry = adapter.AddCommanding();

Then need a way of getting the ICommandRegistry via the IWebHostBuilder builder I guess, so I can register query handlers from the other projects.

possible bug in registering handlers

Please see this gist for a repo - https://gist.github.com/cjrpriest/b536bb69630fd8ff60b1e0089b5abae1

I get this exception thown on line 37:

System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
   at System.ThrowHelper.ThrowKeyNotFoundException()
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at AzureFromTheTrenches.Commanding.Implementation.CommandExecuter.<ExecuteCommandWithHandlers>d__10`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at AzureFromTheTrenches.Commanding.Implementation.CommandExecuter.<ExecuteAsync>d__9`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at AzureFromTheTrenches.Commanding.Implementation.CommandExecuter.<ExecuteAsync>d__9`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at AzureFromTheTrenches.Commanding.Implementation.CommandDispatcher.<DispatchAsync>d__6`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at AzureFromTheTrenches.Commanding.Implementation.CommandDispatcher.<DispatchAsync>d__5.MoveNext()

Thanks :)

Error executing commandDispatcher.DispatchAsync()

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.