Skip to content

ABaker86/DotNetPluginWebAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DotNetPluginWebAPI

A web API created to move controller and business logic into separate libraries from core service.

Motivation

Work-related experiences have brought to my attention many legacy systems that utilize code intended to accomplish the same task but may be written in different ways even if the code base is written in the same programming language.

Ultimately this results in new and existing developers inadvertently reinventing the wheel for components and systems that have already been developed previously. Therefore, I have created a single Web API and migrated the business logic into separate libraries that can be loaded on application startup.

By doing this, new developers can focus on core business logic and refrain from re-developing common cross-cutting concerns such as logging, infrastructure access (i.e. data persistence), authorization and authentication.

Code style

js-standard-style

Tech/framework used

Built with

Features

This library is intended to be extendable by creating individual class libraries containing Web API controlers, dependency registries, and business logic.

using Plugin.Core;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

public class IndividualPluginRegistry : IRegister
{
    public void Register(IServiceCollection services, IConfiguration configuration)
    {
        services.AddSingleton<IRepository, InMemoryRepository>();
        services.AddHttpClient<UspsHttpClient>((sp, client) =>
        {
          var endpoints = sp.GetRequiredServices<IOptions<ProviderSettings>>().value;
          client.BaseAddress = new Uri(endpoints.Provide["Uri"];

          var apiId = endpoints.Provider["ApiId"];
          var apiKey = endpoints.Provider["ApiKey"];
          var apiToken = Convert.ToBase64String(Encoding.Default.GetBytes($"{apiId}:{apiKey}"));
          
          client.DefaultRequestHeaders.Add("Authorization", $"Basic {apiToken}");
        }
    }

Tests

Tests have been created as part of the GreenHorn.NameParser project using the Microsoft Testing Framework.

Example:

How to use?

  1. Start by cloning this project into Visual Studio.
  2. Build the project.
    • Terminal dotnet clean && dotnet build
  3. Copy the resulting Plugin.Example1.dll into your Plugin.API prject executing directory under the "Plugins" directory.
  4. Debug the project Plugin.API
  5. If your browser does not opnen on its own: Navigate to https://localhost:7050/swagger/index.html

Contribute

Contributions are not expected but always welcome!

Contribution Guidelines

Please ensure your pull request adheres to the following guidelines:

  • Alphabetize your entry.
  • Search previous suggestions before making a new one, as yours may be a duplicate.
  • Suggested READMEs should be beautiful or stand out in some way.
  • Make an individual pull request for each suggestion.
  • New categories, or improvements to the existing categorization are welcome.
  • Keep descriptions short and simple, but descriptive.
  • Start the description with a capital and end with a full stop/period.
  • Check your spelling and grammar.
  • Make sure your text editor is set to remove trailing whitespace.

Thank you for your suggestions!

About

A web API created to move controller and business logic into separate libraries from core service.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages