| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
SimpleProxy solves the problem of Aspect Orientated Programming (AoP) in Net Core. It builds on the current Net Core Dependency Injection functions to extend it, providing Proxy services with a very small learning curve.
Wikipedia describes AOP as the following:
"In computing, aspect-oriented programming (AOP) is a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns. It does so by adding additional behavior to existing code (an advice) without modifying the code itself..."
Source: https://en.wikipedia.org/wiki/Aspect-oriented_programming
PostSharp is a long established and mature solution for doing what SimpleProxy does. It allows you to add additional functionality to your classes without spoiling them with repetitive boilerplater code. The fundamental difference is that PostSharp injects its code AFTER compilation, changing the the binaries that are output with additional code. SimpleProxy will wrap your code at runtime, so debugging is easy, and the changes more transparent to a developer. In short, SimpleProxy makes things more obvious.
Visit https://www.nuget.org/packages/SimpleProxy/1.0.1 and download the latest binary
Install directly into your project using: Install-Package SimpleProxy -Version 1.0.1 in your Nuget Package Manager
Creating proxies for objects is not straightforward. One of the most common frameworks for doing so is (and has been for a long time) Castle Core. (https://github.com/castleproject/Core). Infact, Castle Core is used as a fundamental building block for this project. Documentation can be difficult to find for Castle Core and its not straightforward to work with on its own.
SimpleProxy is designed to simplify the whole process. Interception is done in just a few steps:
public class MyCustomAttribute : MethodInterceptionAttribute
{
public MyCustomAttribute()
{
}
}
public class MyCustomInterceptor : IMethodInterceptor
{
public void BeforeInvoke(InvocationContext invocationContext)
{
}
public void AfterInvoke(InvocationContext invocationContext, object methodResult)
{
}
}
// Configure the Service Provider
var services = new ServiceCollection();
// Enable SimpleProxy
services.EnableSimpleProxy(p => p.AddInterceptor<MyCustomAttribute, MyCustomInterceptor>());
services.AddTransientWithProxy<ITestClass, TestClass>();
SimpleProxy uses the default Microsoft.Extensions.DependencyInjection library built into ASP Net Core to register interceptors and then intercept method calls based on the attributes applied to your methods. Methods are intercepted with YOUR own code either before and/or after a method call.
Interceptors are registered in the Microsoft DI framework using the EnableSimpleProxy extension method on IServiceCollection. The AddInterceptor<T,T2>() method uses the fluent interface so it can be chained for easier configuration.
// Configure the Service Provider
var services = new ServiceCollection();
// Enable SimpleProxy
services.EnableSimpleProxy(p => p
.AddInterceptor<MyCustomAttribute, MyCustomInterceptor>()
.AddInterceptor<MyCustomAttribute2, MyCustomInterceptor2>());
...
...
...
...
...
...
...
| Back | FazBrowse Home | New Git URL |