Skip to content

salman-basmechi/reguto

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
        }
    }
}