Resurrect.AspNetCore
0.0.2
See the version list below for details.
dotnet add package Resurrect.AspNetCore --version 0.0.2
NuGet\Install-Package Resurrect.AspNetCore -Version 0.0.2
<PackageReference Include="Resurrect.AspNetCore" Version="0.0.2" />
paket add Resurrect.AspNetCore --version 0.0.2
#r "nuget: Resurrect.AspNetCore, 0.0.2"
// Install Resurrect.AspNetCore as a Cake Addin #addin nuget:?package=Resurrect.AspNetCore&version=0.0.2 // Install Resurrect.AspNetCore as a Cake Tool #tool nuget:?package=Resurrect.AspNetCore&version=0.0.2
Resurrect
Resurrect is a package that allows you to serialize a function for storage or transmission. The serialized function can be resurrected and executed in a different environment.
Table of Contents
Installation
dotnet add package Resurrect
Or simply search for Resurrect
in the NuGet gallery.
To use the package in ASP.NET Core projects, install the Resurrect.AspNetCore
package.
dotnet add package Resurrect.AspNetCore
Or simply search for Resurrect.AspNetCore
in the NuGet gallery.
Features
- Serialize a function to any format (JSON, XML, binary, etc.)
- Resurrect the serialized function and execute it
- Supports functions with parameters
- Supports DI in the resurrected function
- Supports async functions
- Supports functions with return values
The execution environment can be different from the serialization environment. However it must have access to the assembly that contains the method and dependencies of the method.
<sup>The function is technically not serialized. Instead, all the information required to execute the function is serialized. This includes the method name, class name, assembly name, and parameters of the method. The function is resurrected by using reflection to find the method and class, and then invoking the method with the parameters.</sup>
Usage
Start by serializing a function using the SerializableFunction.Serialize
method. The method takes a lambda expression as an argument. The lambda expression should be a function call to the method you want to serialize. The method can be a static method or an instance method.
var function = SerializableFunction.Serialize<TestService>(service => service.TestMethod("Hello, World!"));
var serializedFunction = JsonSerializer.Serialize(function);
The serialized function can be stored in a database, file, or transmitted over the network. To resurrect the function, use the Resurrector
class.
var deserializedFunction = JsonSerializer.Deserialize<SerializableFunction>(serializedFunction);
var resurrector = new Resurrector(new ResurrectionOptions
{
FunctionResolver = new ServiceCollectionFunctionResolver(serviceProvider),
ParameterResolver = new JsonParameterResolver()
});
resurrector.Invoke(deserializedFunction);
The FunctionResolver
property of the ResurrectionOptions
class is used to resolve the class instance of the method. The ParameterResolver
property is used to resolve the parameters of the method. The ServiceCollectionFunctionResolver
class is a built-in function resolver that uses the IServiceProvider
to resolve the class instance. The JsonParameterResolver
class is a built-in parameter resolver that uses JSON to resolve the parameters of the method.
Note: The ServiceCollectionFunctionResolver
and JsonParameterResolver
class requires the Resurrect.AspNetCore
package.
ASP.NET Core Usage
To use Resurrect in ASP.NET Core projects, add the Resurrect.AspNetCore
package to your project. The package provides a built-in function resolver and parameter resolver for ASP.NET Core projects.
services.AddResurrect();
The AddResurrect
method adds the ServiceCollectionFunctionResolver
and JsonParameterResolver
to the DI container. The Resurrector
class will automatically use these resolvers when resolving the function and parameters.
To use the Resurrector
class in your controller, inject the Resurrector
class into the controller.
public class TestController : ApiController
{
private readonly Resurrector _resurrector;
public TestController(Resurrector resurrector)
{
_resurrector = resurrector;
}
[HttpPost]
public IActionResult ExecuteFunction(SerializedFunction serializedFunction)
{
_resurrector.Invoke(deserializedFunction);
return Ok();
}
}
To use other resolvers, configure the ResurrectionOptions
class in the AddResurrect
method.
services.AddResurrect(options =>
{
options.FunctionResolver = new CustomFunctionResolver();
options.ParameterResolver = new CustomParameterResolver();
});
TODO
- Test coverage
- Handle versioning for the package better
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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 | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.0)
- Resurrect (>= 0.0.2)
- System.Text.Json (>= 8.0.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.