Skip to content

This Project is just a workaround to support dynamic interceptions with Lamar as interceptors are not supported yet natively by Lamar.

Notifications You must be signed in to change notification settings

yassinebennani/Lamar.DynamicInterception

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Lamar.DynamicInterception

This project is an adapation of StructureMap.DynamicInterception. This Project is just a workaround to support dynamic interceptions with Lamar as interceptors are not supported yet natively by Lamar.

Available on NuGet latest version.

Package manager console command for installation: Install-Package Lamar.DynamicInterception

Interceptor Behavior Definition

namespace App
{
    using Lamar.DynamicInterception;
    using System;
    using System.Collections.Generic;
    using System.Threading.Tasks;
    
    public sealed class CustomInterceptionBehavior : IAsyncInterceptionBehavior
    {
        public async Task<IMethodInvocationResult> InterceptAsync(IAsyncMethodInvocation methodInvocation)
        {
            MethodInfo method = methodInvocation.MethodInfo;

            return await methodInvocation.InvokeNextAsync().ConfigureAwait(false);
        }
    }
}

Service Interfaces Definitions

public interface IWidget
{
   String GetTitle();
}

public interface IWidgetProxy : IWidget
{
    //you should define this proxy Interface to act just as a proxy.
    //Never add any definition method in this interface.
    //All definitions methods should go into IWidget.
    //I created this interface to handel activator interception
    //because activator interceptor is not supported yet
    //by Lamar.
}

Service Implementation

public class Widget : IWidget, IWidgetProxy
{
   public String GetTitle()
   {
       return "My name is DefaultWidget"
   }
}

Service Registration

var container = new Container(services =>
{
   services.For<IWidgetProxy>().Use<Widget>;
   services.For<IWidget>.InterceptWith<IWidget, IWidgetProxy>(typeof(CustomInterceptionBehavior))
});

About

This Project is just a workaround to support dynamic interceptions with Lamar as interceptors are not supported yet natively by Lamar.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages