Meat Loaf (/inversionhourglass/Rougamo), a compile-time AOP component , no need to initialize at application startup , and no need for cumbersome configuration ; support for all kinds of methods (synchronous and asynchronous , static and instance , constructor/property/normal methods ) ; provides a simple and easy to use Attribute application , but also provides a class of AspectJ expressions in the bulk of the application of the rules .
4.0.1 Updates
existReviews of articles released in version 4.0 In the middle of this update, a friend gave feedback about an issue that prevents you from viewing the value of a variable inside a method when debugging. This update is to fix this issue. 4.0.1 does not contain any other changes, and has no effect on those who disable Meat Loaf when debugging, so you can upgrade at your discretion.
Meat Loaf IoC/DI Expansion
4.0.1 was not going to be blogged, the content was over in one sentence, but then I remembered that IoC extensions were also released some time ago, so I thought I'd just combine them together and write a blog.
The most common problem you all encounter when using Meat Loaf is probably how to interact with IoC. Nowadays the mainstream dynamic proxies themselves need IoC to complete, so dynamic proxies have a natural advantage in IoC interaction, while Meat Loaf does not rely on IoC to complete at compile time, so it is not very convenient to interact with IoC. But inconvenient is not impossible. Previously there have been friends who have implemented IoC access in their own projects, such as, FreeSql. Considering that the use of IoC is very common nowadays, several new extension packages for common IoCs have been added.
There is currently support for only two of the most commonly used IoC components, one being the official MicrosoftThe other is
Autofac
, contains four main NuGet:
included among theseAspNetCore
The two NuGet's at the end are dedicated to AspNetCore (crap out oh) and the other two NuGet's are for theUniversal Host(Generic Host) and Framework scenarios.
Version number description
When referencing these NuGet packages, you will find that they all contain many versions. This is not caused by fast iterative version updates or wrongly set version numbers, there are corresponding rules for version numbers, and their major version numbers follow the NuGet major version number of the corresponding IoC component. Microsoft's two official extension packs' major version numbers follow.*
The major version number (and also the version of the .NET SDK) of theAutofac
The major version numbers of the two extension packages follow theAutofac
The master version number of the
Quick Start
Here's a quick demonstration of how to use the corresponding extension packs directly in code.
// Register Rougamo (note: if you don't use the IoC/DI functionality, Rougamo doesn't require a registration operation by default)
public static void Main(string[] args)
{
var builder = (args);
// ... Omit the other steps
(); var builder = (args); // ...
// ... Omit other steps
}
// Get the IServiceProvider instance and use it in the cutout type
public class TestAttribute : MoAttribute
{
public override void OnEntry(MethodContext context)
{
// Get the IServiceProvider instance using the extension method GetServiceProvider
var services = ();
// Use the IServiceProvider
var xxx = <IXxx>();
}
}
// Register Rougamo (note: if you don't use the IoC/DI functionality, Rougamo doesn't require a registration operation by default)
public static void Main(string[] args)
{
var builder = ();
// ... Omit the other steps
(services => ()); // ...
// ... Omit other steps
}
// Get the IServiceProvider instance and use it in the cutout type
public class TestAttribute : MoAttribute
{
public override void OnEntry(MethodContext context)
{
// Get the IServiceProvider instance using the extension method GetServiceProvider
var services = ();
// Use the IServiceProvider
var xxx = <IXxx>();
}
}
// Register Rougamo (note: if you don't use the IoC/DI functionality, Rougamo doesn't require a registration operation by default)
public static void Main(string[] args)
{
var builder = (args);
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
.ConfigureContainer<ContainerBuilder>(builder =>.
{
();
});
// Registering the IHttpContextAccessor is also required
(); }); // Registering the IHttpContextAccessor is also required.
}
// Get the ILifetimeScope instance in the cutout type and use it
public class TestAttribute : MoAttribute
{
public override void OnEntry(MethodContext context)
{
// Get the ILifetimeScope instance using the extension method GetAutofacCurrentScope
var scope = ();
// Use ILifetimeScope
var xxx = <IXxx>();
}
}
// enrollmentRougamo(classifier for sums of money:If you don't use theIoC/DIfunctionality,Rougamo默认是不需要enrollment操作的)
public static void Main(string[] args)
{
var builder = ();
builder
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
.ConfigureContainer<ContainerBuilder>(builder =>
{
();
});
}
// Get in the cutout typeIServiceProviderinstance and use the
public class TestAttribute : MoAttribute
{
public override void OnEntry(MethodContext context)
{
// Using Extended MethodsGetAutofacCurrentScopegainILifetimeScopean actual example
var scope = ();
// utilizationILifetimeScope
var xxx = <IXxx>();
}
}
Earlier Framework projects, as well as WinForm, WPF and other projects may not use the generic host (Generic Host), this time using theIt will be more straightforward to create the initialization
ContainerBuilder
directly after calling theRegisterRougamo
Extending the method is sufficient.
var builder = new ContainerBuilder();
();
more
For more information on the Meat Loaf IoC/DI extensions please visit (/inversionhourglass/), feedback and PR submissions are welcome.