Skip to content

ddd-tw/DDDTW.PollyAttribute.Core

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

DDDTW.PollyAttribute.Core

This repo tries to treat Polly to be a .net attribute.

DDDTW.PollyAttribute.Core

Provision

There are some differences in .net framework and .net core; If your project is based on .net core, congratulation you! you will feel easy to integrate PollyAttribute into your project.

You just need to install DDDTW.PollyAttribute.Core nuget package. After you install package success, then please add a line of code in Program.cs

 public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
               .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                })
                .UseServiceProviderFactory(new DynamicProxyServiceProviderFactory());

Then you can add PollyAttribute on specific method:

    public interface IProductService
    {
        string GetProductName();

        string GetProductName_Failback();
    }

    public class ProductService : IProductService
    {
        private static int counter = 0;

        [PollyAsync(FallBackMethod = nameof(GetProductName_Failback), IsEnableCircuitBreaker = true)]
        public string GetProductName()
        {
            if (counter++ >= 3)
                throw new Exception();
            return "Prd";
        }

        public string GetProductName_Failback()
        {
            return "Prd Fall_back";
        }
     }

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages