logo
down
shadow

Implementing auditing using Autofac if it support method interception?


Implementing auditing using Autofac if it support method interception?

By : zabeena ali
Date : November 20 2020, 07:00 PM
I think the issue was by ths following , AutoFac has interception capabilities, which rely on Castle DynamicProxy library (same that Castle Windsor uses). Check this website for examples of usage.
code :


Share : facebook icon twitter icon
Autofac 2.6.1 AOP Interception

Autofac 2.6.1 AOP Interception


By : Irving Rivera
Date : March 29 2020, 07:55 AM
should help you out AutofacContrib.DynamicProxy2 is working and yes there is not much activity in that space. There are couple of specific issues which are open but they are specific.
http://code.google.com/p/autofac/issues/detail?id=359
Autofac using DynamicProxy2 Interception with WcfIntegration

Autofac using DynamicProxy2 Interception with WcfIntegration


By : Alexander Wu
Date : March 29 2020, 07:55 AM
With these it helps As this has been raised as a bug on autofac bugtracker, If no one can see a workaround, I'll mark this as the answer. They have uploaded a console app reproducing the exact scenario.
http://code.google.com/p/autofac/issues/detail?id=361&q=dynamicproxy2
Autofac Interception with custom attributes

Autofac Interception with custom attributes


By : user3546179
Date : March 29 2020, 07:55 AM
Hope this helps Although the use of attributes to enrich types with metadata to feed cross-cutting concerns with data to use isn't bad, the use of attributes to mark classes or methods to run some cross-cutting concern usually is.
Marking code with the attribute like you shown has some serious downsides:
code :
public class LoggingCommandHandlerDecorator<T> : ICommandHandler<T>
{
    private readonly ILogger logger;
    private readonly ICommandHandler<T> decoratee;
    public LoggingCommandHandlerDecorator(ILogger logger, ICommandHandler<T> decoratee) {
        this.logger = logger;
        this.decoratee = decoratee;
    }

    public void Handle(T command) {
        this.logger.Log("Handling {0}. Data: {1}", typeof(T).Name,
            JsonConvert.SerializeObject(command));
        this.decoratee.Handle(command);
    }
}
[Permission(Permissions.Crm.ManageCompanies)]
public class BlockCompany : ICommand {
    public Guid CompanyId;
}
public class PermissionCommandHandlerDecorator<T> : ICommandHandler<T>
{
    private static readonly Guid requiredPermissionId =
        typeof(T).GetCustomAttribute<PermissionAttribute>().PermissionId;

    private readonly IUserPermissionChecker checker;
    private readonly ICommandHandler<T> decoratee;

    public PermissionCommandHandlerDecorator(IUserPermissionChecker checker,
        ICommandHandler<T> decoratee) {
        this.checker = checker;
        this.decoratee = decoratee;
    }

    public void Handle(T command) {
        this.checker.CheckPermission(requiredPermissionId);
        this.decoratee.Handle(command);
    }
}
Autofac method level interception with Castle DynamicProxy in .NET Core 2

Autofac method level interception with Castle DynamicProxy in .NET Core 2


By : Kim Chan
Date : March 29 2020, 07:55 AM
To fix the issue you can do The invocation parameter of the Intercept method contains a Method property which is a MethodInfo of the method currently intercepted.
You can use this property to do what you want.
code :
public void Intercept(IInvocation invocation)
{
    if (invocation.MethodInvocationTarget.Name != nameof(ISomeService.Create))
    {
        invocation.Proceed();
        return;
    }
    using (var transaction = ...)
    {
        try
        {
            invocation.Proceed();
            transaction.Commit();
        }
        catch
        {
            transaction.Rollback();
        }
        finally
        {
            transaction.Dispose();
        }
    }
}
if (!invocation.MethodInvocationTarget
               .CustomAttributes
               .Any(a => a.AttributeType == typeof(TransactionalAttribute)))
Interception on .NET Core 2.0 Web API Controller By Using Autofac

Interception on .NET Core 2.0 Web API Controller By Using Autofac


By : Chumputy
Date : March 29 2020, 07:55 AM
will help you When working with interception of type, methods should be declared as virtual
code :
// GET api/values
[HttpGet]
public virtual IEnumerable<string> Get()
{
    return new string[] { "value1", "value2" };
}
public void ConfigureServices(IServiceCollection services)
{
    services
        .AddMvc()
        .AddControllersAsServices();
}
Related Posts Related Posts :
  • Write-Through Cache
  • How do you load the app.config file into a DLL
  • Validation in ASP.net
  • Any ASP.Net benchmark tool?
  • Generics vs boxing
  • "Does not implement IControllerFactory.CreateController" in Visual Studio 2010
  • Tabs for a ASP.NET website
  • AccountManagement.UserPrincipal.Current takes 5 seconds
  • Will linq to sql work in an asp.net 2.0 web application?
  • How to use XML namespace prefixes without xmlns="..." everywhere? (.NET)
  • Retrieving OS name
  • .Net Regular Expression to get parenthetical text at end of <p> tags
  • The Project Location is Not Trusted error in Visual Studio
  • how to tell if a photo was taken in landscape or portrait? JPEG .NET metadata orientation
  • Winform and ValidateChildren()
  • Why need to mention "Supported by the .NET Compact Framework" for classes members?
  • Pass MSI parameters to .NET installer class
  • How to print stack trace of StackOverflowException
  • OnPropertyChange as an Alternative to Triggers in Entity Framework
  • "User Friendly" .net compatible Regex/Text matching tools?
  • Non-Ascii characters not supported by .net?
  • Linq SqlMethods.Like fails
  • To check whether the SQL server DB is working properly or not
  • What is the Difference between GC.GetTotalMemory(false) and GC.GetTotalMemory(true)
  • Which version of .NET is available for Xbox 360?
  • Validation (with custom ErrorTemplate) for a DataTemplate
  • is the threadpool shared - .net
  • WPF RichTextBox - Formatting of typed text
  • "ResizeEnd" equivalent for usercontrols
  • How work with common utils project
  • Using image resource in XAML markup?
  • How to write an altered COM Structured Storage file to Disk?
  • How can a static class be resolved by the Unity Framework?
  • How to flush DNS cache in Windows Mobile programmatically?
  • how to set autoplay=true in google audio player?
  • Edit dialog, with bindings and OK/Cancel in WPF
  • What does MailMessage.IsBodyHtml do?
  • C# Class Library wont register for COM
  • Robust DateTime parser library for .NET
  • MySql BulkCopy/Insert from DataReader
  • How do I allow all users access to one route within a website with integrated auth?
  • Reading from a oracle temp table in a separate procedure than the one it was populted in
  • Recommendations for IPC between parent and child processes in .NET?
  • How to get a majority color in an image?
  • Rename parameter in a WCF client interface
  • In WPF: Children.Remove or Children.Clear doesn't free objects
  • Convincing Management to use WCF
  • How to access a property in a class used to implement IDispatchMessageInspector on a WCF service (server side)?
  • How to generate distinct random numbers per distinct threads in .NET?
  • Using a DataSet instead of custom business entities in soa and n-tier architecture
  • .NET assembly loading problem
  • Code Trivia: optimize the code for multiple nested loops
  • Is it safe to use ThreadStatic variable in WCF?
  • Back button in ajax update panel not working
  • Problem using ‘useLegacyV2RuntimeActivationPolicy’ & supportedRuntime in an application
  • I've built a Windows service as "Any CPU". Why does it run in 32-bit mode on my 64 bit machine?
  • Is there any way to disable the "double-click to copy" functionality of a .NET label?
  • Verify installation of ASP.NET Ajax Extension
  • Allow IExtenderProvider control to attach to controls on a UserControl
  • Hooking into AppInitialize with WCF service
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk