Kimono 0.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Kimono --version 0.1.0                
NuGet\Install-Package Kimono -Version 0.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Kimono" Version="0.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Kimono --version 0.1.0                
#r "nuget: Kimono, 0.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Kimono as a Cake Addin
#addin nuget:?package=Kimono&version=0.1.0

// Install Kimono as a Cake Tool
#tool nuget:?package=Kimono&version=0.1.0                

Kimono

DOTNET Build

<pre> _ _
| | ()
| | ___ _ __ ___ ___ _ __ ___
| |/ / | '
` _ \ / _ | '_ \ / _ \ | <| | | | | | | () | | | | () | ||__|| || ||_/|| ||_/ </pre>

Kimono is a dynamic proxy framework that allows intercepting methods and properties. Currently in development! Working on generating MSIL for out and ref parameters definitions. See below for examples.

public class Program
{
    public void Main(string[] args)
    {
        var examples = new KimonoExamples();
        examples.NoTargetWithCallbackInterceptorExample();
        examples.TargetWithCallbackInterceptorExample();
        examples.NoTargetWithHandlersInterceptorExample();
        examples.TargetWithHandlersInterceptorExample();
        examples.NoTargetWithInvocationChainInterceptorExample();
        examples.TargetWithInvocationChainInterceptorExample();
    }
}
public class KimonoExamples
{
    public void NoTargetWithCallbackInterceptorExample()
    {
        var interceptor = Interceptor.WithCallback<IRepository>(context =>
        {
            if (context.MemberName == "Baz")
            {
                context.ReturnValue = context.GetParameter<Model>("model");
            }

            if (context.MemberName == nameof(IRepository.Save))
            {
                context.InvokeTarget();
            }
        });

        interceptor.Save(new Model { Id = 20 });
    }
    public void TargetWithCallbackInterceptorExample()
    {
        var interceptor = Interceptor.TargetedWithCallback<IRepository, Repository>(new Repository(), context =>
        {
            context.InvokeTarget();

            if (context.MemberName == nameof(IRepository.Save))
            {
                if (context.ReturnValue is false)
                {
                    //Log failure
                }
            }
        });

        interceptor.Save(new Model { Id = 20 });
    }
    public void NoTargetWithHandlersInterceptorExample()
    {
        var interceptor = Interceptor.WithHandlers<IRepository>(new BazReturnInvocationHandler());

        interceptor.Save(new Model { Id = 20 });
    }
    public void TargetWithHandlersInterceptorExample()
    {
        var interceptor = Interceptor.TargetedWithHandlers<IRepository, Repository>(new Repository(), new BazReturnInvocationHandler());

        interceptor.Save(new Model { Id = 20 });
    }
    public void NoTargetWithInvocationChainInterceptorExample()
    {
        var interceptor = Interceptor.TargetedWithInovcationChain<IRepository, Repository>(new Repository(), builder =>
        {
            builder.Add((next, context) =>
            {
                context.InvokeTarget();

                if (context.MemberName == nameof(IRepository.Save))
                {
                    if (context.ReturnValue is false)
                    {
                        //Log failure
                        return;
                    }
                }

                next(context);
            });
        });

        interceptor.Save(new Model { Id = 20 });
    }
    public void TargetWithInvocationChainInterceptorExample()
    {
        var interceptor = Interceptor.WithInovcationChain<IRepository>(builder =>
        {
            builder.Add((next, context) =>
            {
                if (context.MemberName == nameof(IRepository.Save))
                {
                    context.ReturnValue = true;
                }

                // Call next regardless of condition
                next(context);
            });
        });

        interceptor.Save(new Model { Id = 20 });
    }
    private class BazReturnInvocationHandler : IInvocationHandler
    {
        public void Handle(IInvocationContext context)
        {
            if (context.MemberName == "Baz")
            {
                context.ReturnValue = context.GetParameter<Model>("model");
            }

            if (context.MemberName == nameof(IRepository.Save))
            {
                if (context.ReturnValue is false)
                {
                    //Log failure
                    return;
                }
            }
        }
    }
}
public class Model
{
    public int Id { get; set; }
}
public interface IRepository
{
    bool Save(Model model);
}
public class Repository : IRepository
{
    public bool Save(Model model)
    {
        return true;
    }
}
public interface ILog
{
    void Log(string message);
}
public class Service
{
    private readonly ILog _log;
    private readonly IRepository _repo;
    public Service(ILog log, IRepository repo)
    {
        _log = log;
        _repo = repo;
    }
    public Model SaveModel(Model model)
    {
        try
        {
            var saved = _repo.Save(model);
            if (!saved)
            {
                _log.Log("Failed to save");
            }
            return model;
        }
        catch (Exception ex)
        {
            _log.Log(ex.Message);
            throw;
        }
    }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Kimono:

Package Downloads
Overmock

Overmock is a mocking framework that allows for very robust mocking configuration and validation.

Kimono.Extensions.DependencyInjection

Kimono.Extensions.DependencyInjection contains extension methods for adding of interceptors to DI.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.1.1 185 8/15/2024
0.1.0 175 8/9/2024
0.0.12 321 3/27/2024
0.0.11-RC01 252 10/16/2023
0.0.10 195 10/11/2023
0.0.9 203 9/17/2023
0.0.9-RD01 174 8/28/2023
0.0.9-RC03 145 9/15/2023
0.0.9-RC02 168 8/30/2023
0.0.8 222 8/27/2023
0.0.7 196 8/27/2023
0.0.7-RC05 109 8/25/2023
0.0.7-RC04 136 8/24/2023
0.0.7-RC03 141 8/22/2023
0.0.7-RC02 131 8/19/2023
0.0.7-RC01 135 8/16/2023
0.0.6 179 8/15/2023
0.0.6-RC01 140 8/14/2023
0.0.5 173 8/14/2023
0.0.4 188 8/13/2023
0.0.3 176 8/13/2023
0.0.1 181 8/13/2023
0.0.1-RC03 147 8/13/2023
0.0.1-RC02 144 8/13/2023
0.0.1-RC01 156 8/11/2023

Finished up Kimono slim. Rewrite (restructure and some rewrite) and trimming most of the unneeded classes.