Skip to content

kitpymes/template-netcore-api

Repository files navigation

Kitpymes.Core.Api

Extensiones y herramientas comunes utilizadas por la Api

Build Status NuGet Status NuGet Download License: MIT Size Repo Last Commit

📋 Requerimientos

  • Visual Studio >= 2019

  • NET TargetFramework >= net5.0

  • Net Core SDK >= 5.0.100

  • C# >= 9.0

  • Conocimientos sobre Inyección de Dependencias

🔧 Instalación

Se puede instalar usando el administrador de paquetes Nuget o CLI dotnet.

Nuget

Install-Package Kitpymes.Core.Api

CLI dotnet

dotnet add package Kitpymes.Core.Api

⌨️ Código

ApiVersioning

public static class ApiVersioningApplicationBuilderExtensions
{
    public static IApplicationBuilder LoadApiVersioning(this IApplicationBuilder application)
    {}
}
public static class ApiVersioningServiceCollectionExtensions
{
    public static IServiceCollection LoadApiVersioning(
        this IServiceCollection services,
        IConfiguration configuration,
        IApiVersionReader? apiVersionReader = null,
        IApiVersionConventionBuilder? conventions = null)
    {}

    public static IServiceCollection LoadApiVersioning(
            this IServiceCollection services,
            Action<ApiVersioningOptions> options)
    {}

    public static IServiceCollection LoadApiVersioning(
        this IServiceCollection services,
        ApiVersioningSettings settings)
    {}
}
public class ApiVersioningOptions
{
    public ApiVersioningOptions WithEnabled(bool enabled)
    {}

    public ApiVersioningOptions WithMajorVersion(int version)
    {}

    public ApiVersioningOptions WithMinorVersion(int version)
    {}

    public ApiVersioningOptions WithAssumeDefaultVersionWhenUnspecified(bool assume)
    {}

    public ApiVersioningOptions WithReportApiVersions(bool report)
    {}

    public ApiVersioningOptions WithSubstituteApiVersionInUrl(bool substitute)
    {}

    public ApiVersioningOptions WithGroupNameFormat(string nameFormat)
    {}

    public ApiVersioningOptions WithApiVersionReader(IApiVersionReader apiVersionReader)
    {}

    public ApiVersioningOptions WithConventions(IApiVersionConventionBuilder conventions)
    {}
}
public class ApiVersioningSettings
{
    public bool? Enabled { get;  set; }

    public int? MajorVersion { get;  set; }

    public int? MinorVersion { get;  set; }

    public bool? AssumeDefaultVersionWhenUnspecified { get;  set; }

    public bool? ReportApiVersions { get;  set; }

    public bool? SubstituteApiVersionInUrl { get;  set; }

    public string? GroupNameFormat { get;  set; }

    [JsonIgnore]
    public IApiVersionReader? ApiVersionReader { get;  set; }

    [JsonIgnore]
    public IApiVersionConventionBuilder? Conventions { get;  set; }
}
public enum ApiVersioningStatus
{
    Alpha,

    Beta,

    RC,

    Stable,
}

AppSession

public static class DependencyInjectionSession
{
    public static IServiceCollection LoadSession(
        this IServiceCollection services,
        Action<SessionOptions> options)
    {}

    public static IServiceCollection LoadSession(this IServiceCollection services) {}

    public static IApplicationBuilder LoadSession(this IApplicationBuilder application) {}
}
public class SessionOptions
{
    public SessionOptions WithEnabled(bool enabled = true) {}

    public SessionOptions WithMultitenancy(bool enabled = true) {}

    public SessionOptions WithTenants(params Entities.TenantSession[] tenants) {}
}
public class SessionSettings
{
    public bool? Enabled { get;  set; }

    public bool? IsMultitenancy { get;  set; }

    public List<TenantSession> Tenants { get; set; } = new ();
}

Host

public static class InitHost
{
    public static async Task RunAsync<TStartup>(string[] args)
        where TStartup : class
    {}

    public static IHost Build<TStartup>(string[] args)
        where TStartup : class
    {}

    public static IHostBuilder Custom<TStartup>(string[] args)
        where TStartup : class
    {}
}

Result

public class AspNetResult : IActionResult
{
    public AspNetResult(IResult result) => Result = result;

    private IResult Result { get; }

    public async Task ExecuteResultAsync(ActionContext context)
    {}
}

Spa

public static class SpaApplicationBuilderExtensions
{
    public static IApplicationBuilder LoadSpa(
        this IApplicationBuilder application,
        Action<AngularOptions> options)
    {}

    public static IApplicationBuilder LoadSpa(
        this IApplicationBuilder application,
        AngularSettings settings)
    {}
}
public static class SpaServiceCollectionExtensions
{
    public static IServiceCollection LoadSpa(
        this IServiceCollection services,
        string rootPath = DefaultRootPath)
    {}
}
public abstract class SpaBaseSettings
{
    public bool? { get; set; }

    public string? SourcePath { get; set; }

    public string? NpmScript { get; set; }

    public string? BaseUri { get; set; }
}
public class SpaOptions
{
    public SpaOptions WithEnabled(bool enabled = true)
    {}

    public SpaOptions WithAngular(Action<AngularOptions> options)
    {}

    public SpaOptions WithAngular(AngularSettings settings)
    {}
}
public class SpaSettings
{
    public bool? Enabled { get; set; }

    public AngularSettings? AngularSettings { get; set; }
}
public class AngularOptions
{
    public AngularOptions WithEnabled(bool enabled = true)
    {}

    public AngularOptions WithSourcePath(string sourcePath = AngularSettings.DefaultSourcePath)
    {}

    public AngularOptions WithNpmScript(string npmScript = AngularSettings.DefaultNpmScript)
    {}

    public AngularOptions WithBaseUri(string baseUri = AngularSettings.DefaultBaseUri)
    {}
}
public class AngularSettings : SpaBaseSettings
{}

Swagger

public static class SwaggerApplicationBuilderExtensions
{
    public static IApplicationBuilder LoadSwagger(this IApplicationBuilder application)
    {}
}
public static class SwaggerOperationFilterContextExtensions
{
    public static IEnumerable<TAttribute> GetControllerAndActionAttributes<TAttribute>(this OperationFilterContext context) 
        where TAttribute : Attribute
    {}
}
public static class SwaggerServiceCollectionExtensions
{
    public static IServiceCollection LoadSwagger(
        this IServiceCollection services,
        Action<SwaggerOptions> options)
    {}

    public static IServiceCollection LoadSwagger(
        this IServiceCollection services,
        SwaggerSettings settings)
    {}
}
public class ApiExplorerDocumentFilter : IDocumentFilter
{
    public ApiExplorerDocumentFilter(IOptions<ApiExplorerOptions> options)
    {  }

    public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
    {  }
}
public class AuthorizationBearerFilter : IOperationFilter
{
    public void Apply(OpenApiOperation operation, OperationFilterContext context)
    {}
}
public sealed class DefaultValuesFilter : IOperationFilter
{
    public void Apply(OpenApiOperation operation, OperationFilterContext context)
    {}
}
public sealed class StatusCodesFilter : IOperationFilter
{
    public void Apply(OpenApiOperation operation, OperationFilterContext context)
    {}
}
public sealed class SupportedLanguagesFilter : IOperationFilter
{
    public SupportedLanguagesFilter(IServiceProvider serviceProvider) 
    {}

    public void Apply(OpenApiOperation operation, OperationFilterContext context)
    {}
}
public sealed class YamlDocumentFilter : IDocumentFilter
{
    private IWebHostEnvironment HostingEnvironment { get; }

    public YamlDocumentFilter(IWebHostEnvironment hostingEnvironment)
    {}

    public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
    {}
}
public class ContactSettings
{
    public string? Name { get; set; }

    public string? Url { get; set; }

    public string? Email { get; set; }
}
public class LicenseSettings
{
    public string? Name { get; set; }

    public string? Url { get; set; }
}
public class SecuritySettings
{
    public string? Title { get; set; }

    public string? Name { get; set; }

    public string? Scheme { get; set; }

    public string? Description { get; set; }

    public int? ParameterLocation { get; set; }

    public int? SecurityType { get; set; }
}
public class SwaggerOptions
{
    public SwaggerOptions WithEnabled(bool enabled = true)
    {}

    public SwaggerOptions WithRoutePrefix(string routePrefix)
    {}

    public SwaggerOptions WithVersion(string version)
    {}

    public SwaggerOptions WithTitle(string title)
    {}

    public SwaggerOptions WithDescription(string description)
    {}

    public SwaggerOptions WithTermsOfServiceUrl(string url)
    {}

    public SwaggerOptions WithContact(ContactSettings contact)
    {}

    public SwaggerOptions WithLicense(LicenseSettings license)
    {}

    public SwaggerOptions WithSecurity(SecuritySettings security)
    {}

    public SwaggerOptions WithXmlComments(Assembly assembly)
    {}
}
public class SwaggerSettings
{
    public bool? Enabled { get; set; }

    public string? RoutePrefix { get; set; }

    public string? Version { get; set; }

    public string? Title { get; set; }

    public string? Description { get; set; }

    public string? TermsOfServiceUrl { get; set; }

    public ContactSettings Contact { get; set; } = new ContactSettings();

    public LicenseSettings License { get; set; } = new LicenseSettings();

    public SecuritySettings Security { get; set; } = new SecuritySettings();

    public Assembly? XmlComments { get; set; }

    [JsonIgnore]
    public string RoutePrefixWithSlash => string.IsNullOrWhiteSpace(RoutePrefix) ? string.Empty : RoutePrefix + "/";
}

🛠️ Construido con

✒️ Autores

  • Sebastian R Ferrari - Trabajo Inicial - kitpymes

📄 Licencia

  • Este proyecto está bajo la Licencia LICENSE

🎁 Gratitud

  • Este proyecto fue diseñado para compartir, creemos que es la mejor forma de ayudar 📢
  • Cada persona que contribuya sera invitada a tomar una 🍺
  • Gracias a todos! 🤓

Kitpymes 😊