Skip to content

Latest commit

 

History

History
71 lines (60 loc) · 1.79 KB

README.md

File metadata and controls

71 lines (60 loc) · 1.79 KB

Reguto

Scan and register all dependencies and options automatically based on attributes.

You can get the latest stable release from the nuget.org or from github releases page.

public interface IIdentityService
{
    Task<AuthenticationResponse> AuthenticateAsync(string username, string password);
}

Annotate service class as scoped dependency with ServiceAttribute

[Service]
public class IdentityService : IIdentityService
{
    private readonly IOptions<JwtOptions> options;

    public IdentityService(IOptions<JwtOptions> options)
    {
        this.options = options ?? throw new ArgumentNullException(nameof(options));
    }

    public Task<AuthenticationResponse> AuthenticateAsync(string username, string password)
    {
        throw new NotImplementedException();
    }
}

Annotate options class and determine value section in appSettings.json or other settings file.

[Options("Jwt")]
public class JwtOptions
{
    public string Secret { get; init; }

    public string ExpiryMinutes { get; init; }
}

Register all dependencies and options in startup.

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Reguto.DI.Microsoft;
using Reguto.Options.Microsoft;

namespace Web
{
    public class Startup
    {
        public IConfiguration Configuration { get; }

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddReguto();
            services.ConfigureReguto(Configuration);
        }

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            // configure
        }
    }
}