Coder Social home page Coder Social logo

dotnetgenericwebapi's Introduction

Quick and dirty extension for basic .NET web api (in development)

Configurations

Swagger AUTH

If you require Swagger UI Authentication include following in program.cs:

builder.Services.ConfigureSwaggerWithAuth(configuration, auth = true);

Above configures and setups authentication, use below to automatically fulfill form on user action:

app.ConfigureSwaggerUIWithAuth(configuration, auth = true);

Default auth is set to true, which means that it takes care of basic azure authorization configurations, otherwise at false you have to set it up yourself. To make above defaults work you are required to have below settings in appsettings.json:

"AzureAd": {  
    "Instance": "https://login.microsoftonline.com",  
    "Domain": "xxx.onmicrosoft.com",  
    "TenantId": "{tenantId}}",
    "ClientId": "{clientId}",
    "Scopes": "api://{clientId}, user.read, profile, email, offline_access, openid",
    "CallbackPath": "/signin-oidc",
    "Audience": "clientId",
    "AudienceIDZ": "api://{clientId}",
    "Swagger": {
        "Api": {
            "Name": "My API",
            "Version": "v1"
        },
        "Scopes-optional": "api://{clientId}, user.read, profile, offline_access",
        "Scopes-selected": "api://{clientId}, user.read, profile, openid"
    }
}

ERROR handling

For custom error handling include:

app.ConfigureExceptionMiddlewareExtension();

You can now extend the base class ApiException or BusinessException/ValidationException to use the custom error handler.

Web API layer extendables

Repository layer

To use the extendable repository layer, you have to create your own BaseContext that extends DbBaseContext from the library (DbBaseContext extends DbContext and has all the required base functionalities):

builder.Services.AddDbContext<DbBaseContext, BaseContext>(options =>
    options.UseNpgsql(builder.Configuration["ConnectionStrings:ConnectionString"])

You can now extend EntityCoreRepository where you can find a lot of basic features ready to be used in service layer.

Service layer

To use the extendable service layer, you have to extend BusinessCoreService and there will be basic features ready to be used in controller layer.

NOTE(service layers needs IMapper, IValidator and IBusinessStrategy) :

  • IMapper - used for mapping entites and dto objects
  • IValidator - can be used as validation for input data where u need it, inject DefaultValidator if you do not need it otherwise implement it in your own class
  • IBusinessStrategy - basic service features do not include any logic besides retrieving, adding, filtering, pagination, updating, deletion... for additional rules in each of the listed features implement it in your own class otherwise inject DefaultBusinessStrategy

Controller layer

Only includes a barebones ApiControllerBase and LazyCoreController that includes some of the functionalities from service layer.

Utilities

Web API layer extendables

Additional small utilities:

  • HtmlFormatter - create HTML formats in a building block style
  • HttpConnector - extendable DI for calling HTML documents
  • MailSystem - extendable DI for sending email, requires appsettings.json:
"Mail-System": {
    "Smtp-Client": {
        "Host": "smtp.gmail.com",
        "Port": 587,
        "Credentials": {
            "E-Mail": "[email protected]",
            "Password": "xxx"
        }
   }
}
  • Validator - if you are using the error handling from before, this can be used with ValidationExcetpion and NumberValidator, ObjectValidator, StringValidator to build validations for inputs

dotnetgenericwebapi's People

Contributors

pigi96 avatar

Stargazers

Anže Gregorc avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.