An open API service indexing awesome lists of open source software.

https://github.com/salman-basmechi/reguto

Reguto is a tool for register dependencies and options automatically based on attributes.
https://github.com/salman-basmechi/reguto

c-sharp dependency-injection microsoft-dependency-injection options-configuration reguto

Last synced: about 1 month ago
JSON representation

Reguto is a tool for register dependencies and options automatically based on attributes.

Awesome Lists containing this project

README

        

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

You can get the latest stable release from the [nuget.org](http://www.nuget.org/packages/reguto) or from [github releases page](https://github.com/salmanbasmechi/reguto/releases).

```C#
public interface IIdentityService
{
Task AuthenticateAsync(string username, string password);
}
```

Annotate service class as scoped dependency with ServiceAttribute
```C#
[Service]
public class IdentityService : IIdentityService
{
private readonly IOptions options;

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

public Task AuthenticateAsync(string username, string password)
{
throw new NotImplementedException();
}
}
```

Annotate options class and determine value section in appSettings.json or other settings file.
```C#
[Options("Jwt")]
public class JwtOptions
{
public string Secret { get; init; }

public string ExpiryMinutes { get; init; }
}
```

Register all dependencies and options in startup.
```C#
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
}
}
}
```