Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add Auditing in FunctionMonkey? #25

Closed
imkheong opened this issue Dec 7, 2018 · 2 comments
Closed

How to add Auditing in FunctionMonkey? #25

imkheong opened this issue Dec 7, 2018 · 2 comments

Comments

@imkheong
Copy link

imkheong commented Dec 7, 2018

Hi James

Thanks for building this framework, appreciate the effort and good thinking.

I have a question regarding Auditing ability shown in this article.

I presume that I need the ICommandingDependencyResolverAdapter resolver or ICommandRegistry registry so I can add the Pre, Post and Execute Dispatch hooks. Is there a way that I can do it in FunctionAppConfiguration currently?

Thanks!

@abezverkov
Copy link

Thanks! I hadn't even seen this functionality in the commanding library!
So I dug around the repos and tested this on my example, seems to work:

using FunctionMonkey.Abstractions;
using AzureFromTheTrenches.Commanding;

public class Configuration : IFunctionAppConfiguration, ICommandingConfigurator
{
    ...
    public ICommandRegistry AddCommanding(ICommandingDependencyResolverAdapter dependencyResolver)
        {
            var registry = dependencyResolver.AddCommanding();
            var auditRootOnly = false;
            dependencyResolver
                .AddPreDispatchCommandingAuditor<ConsoleAuditor>(auditRootOnly)
                .AddPostDispatchCommandingAuditor<ConsoleAuditor>(auditRootOnly)
                .AddExecutionCommandingAuditor<ConsoleAuditor>(auditRootOnly);
            return registry;
        }
}

The key here is the Runtime.cs looks to see if your configuration is ICommandingConfigurator and runs the method. If not, it just runs the AddCommanding() extension on the resolver. Also, it throws an error if you don't run the AddCommanding before adding the auditor. The Add... extensions are in the AzureFromTheTrenches.Commanding namespace.

@imkheong
Copy link
Author

Thank you very much @abezverkov for the answer! I managed to get it to work, and it works exactly I expected it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants