Pattern 2.5.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Pattern --version 2.5.2
                    
NuGet\Install-Package Pattern -Version 2.5.2
                    
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="Pattern" Version="2.5.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Pattern" Version="2.5.2" />
                    
Directory.Packages.props
<PackageReference Include="Pattern" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Pattern --version 2.5.2
                    
#r "nuget: Pattern, 2.5.2"
                    
#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.
#:package Pattern@2.5.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Pattern&version=2.5.2
                    
Install as a Cake Addin
#tool nuget:?package=Pattern&version=2.5.2
                    
Install as a Cake Tool

Build Status NuGet NuGet

Introduction

This package aims to facilitate the inclusion of design patterns applied to the Asp.net Core, integrating concepts of AOP (DynamicProxy).

Implemented patterns: Strategy

pattern

Patterns aplicados ao asp.net core.

AOP Pattern

Instructions

1 - Create Custom intercept attribute inheriting from InterceptorAttribute

    public class TestInterceptorAttribute : InterceptorAttribute
    {
        protected override async Task<TResult> HandleInterceptAsync<TResult>(IInvocation invocation, Func<Task<TResult>> result)
        {
            return await result();
        }
    }

2 - Include attribute annotation above the method that needs to be intercepted


    public interface ITestService
    {
        void Teste1();
        void Teste2();
    }

    public class TestService : ITestService
    {
        [TestInterceptor]
        public void Teste1()
        {
        }

        public void Teste2()
        {
        }
    }

3 - Include in ServiceCollection with DependencyIncection with true parameter

services.AddScoppedStrategy<ITestService, TestService>(true);

Or with a different life cycle, according to your need.

Strategy Pattern

Instructions

1 - Include the following code without Startup.cs, as it will not work in its entirety without it.

//Logic implemented according to your code
services.AddSingletonStrategy<IStrategy<Request, Response>, RequestStrategy>();
//OR
services.AddScoppedStrategy<IStrategy<Request, Response>, RequestStrategy>();
//OR
services.services.AddTransientStrategy<IStrategy<Request, Response>, RequestStrategy>();

2 - Implementing the class:

public class RequestStrategy : IStrategy<Request, Response>

public RequestStrategy(...)
{
...
}

public async Task<Response> HandleAsync(Request request, CancellationToken cancellationToken)
{
    return new Response();
}

If you want to implement using the annotation for interceptor, include the annotation of interceptor in the method according to the code below:

[Validator(typeof(TestStrategyRequestValidator))]
public async Task<Response> HandleAsync(Request request, CancellationToken cancellationToken)
{
    return new Response();
}
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 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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.0 2,074 4/3/2025
2.5.2 3,369 1/12/2023
2.5.1 999 1/11/2023
2.5.0 401 12/20/2022
2.4.0 982 8/9/2022
2.3.0 552 8/3/2022
2.2.0 612 7/4/2022
2.1.1 527 6/30/2022
2.1.0 603 4/20/2022
2.0.0 553 4/20/2022
1.0.1 613 3/3/2022
1.0.0 558 3/3/2022
0.5.5 655 2/14/2022
0.5.4 568 2/14/2022
0.5.3 555 2/14/2022
0.5.2 560 2/10/2022
0.5.1 579 2/10/2022
0.5.0 589 2/10/2022
0.4.0 580 2/10/2022
0.3.2 574 2/10/2022
Loading failed