Dependency Injection With Multiple Implementations Of The Same Interface

public void ConfigureServices(IServiceCollection services)
{
  services.AddTransient<AddOperationRepository>();
  services.AddTransient<SubtractOperationRepository>();
  services.AddTransient<MultiplyOperationRepository>();
  services.AddTransient<DivideOperationRepository>();
  services.AddTransient<Func<MathOperationType, IMathOperationRepository>>(serviceProvider => key =>
  {
    switch (key)
    {
      case MathOperationType.Add:
        return serviceProvider.GetService<AddOperationRepository>();
      case MathOperationType.Subtract:
        return serviceProvider.GetService<SubtractOperationRepository>();
      case MathOperationType.Multiply:
        return serviceProvider.GetService<MultiplyOperationRepository>();
      case MathOperationType.Divide:
        return serviceProvider.GetService<DivideOperationRepository>();
      default:
        throw new KeyNotFoundException();
    }
  });
  . . .
}

...
public class ValuesController : ControllerBase  
{  
  private Func<MathOperationType, IMathOperationRepository> _mathRepositoryDelegate;  
  public ValuesController(Func<MathOperationType, IMathOperationRepository> mathRepositoryDelegate)  
  {  
    _mathRepositoryDelegate = mathRepositoryDelegate;  
  }  
  [HttpPost]  
  public ActionResult<OperationResult> Post([FromBody] OperationRequest opRequest)  
  {  
    IMathOperationRepository mathRepository = _mathRepositoryDelegate(opRequest.OperationType);  
    OperationResult opResult = mathRepository.PerformOperation(opRequest);  
    return new ObjectResult(opResult);  
  }  
} 

Source:
https://www.c-sharpcorner.com/article/dependency-injection-with-multiple-implementations-of-the-same-interface/

Enable CORS in .NET Core Web API

// Startup.cs

public void ConfigureServices(IServiceCollection services)
{
        // ...
        CorsConfig(services);
        // ...
}

public void Configure(IApplicationBuilder app, IApiVersionDescriptionProvider provider)
{
        // ...
        CorsConfig(app);        
        // ...
}

readonly string MyAllowSpecificOrigins = "_myAllowSpecificOrigins";
private void CorsConfig(IApplicationBuilder app)
{
    app.UseCors(MyAllowSpecificOrigins);
}
private void CorsConfig(IServiceCollection services)
{
    services.AddCors(options =>
    {
        options.AddPolicy(MyAllowSpecificOrigins,
        builder =>
        {
            builder.WithOrigins("http://localhost.com");
        });
    });
}

edit git commit details

git rebase -i 0abc12def // <- the commit before the one that needs edit
// use vi to change "pick" to "edit" on the commit(s) that need edits, then write/quit
git commit --amend --author="Christopher Snay <email@email.com>"
// write/quit vi
git rebase --continue // <- repeat until all edited commits complete
git push -f

Angular setup

ng new projectname
cd projectname
sudo npm install --save @angular/material @angular/cdk @angular/animations
npm install hammerjs
ng generate component componentname
ng generate service servicename

Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:726)’),)’: /simple/pylint/ >>>>>>>> Could not fetch URL https://pypi.python.org/simple/setuptools/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host=’pypi.python.org’, port=443): Max retries exceeded with url: /simple/setuptools/ (Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:726)’),)) – skipping



// add the following flag to the pip command:

--trusted-host files.pythonhosted.org --trusted-host pypi.org

// or wherever the error indicates a problem in

HTTPSConnectionPool(host='pypi.python.org', port=443)

compare 2 files with Visual Studio

// open cmd
<<<path to Visual Studio\Common7\IDE>>>devenv /diff file1 file2

Or just create a batch file. Example:

@echo off
echo Drag and drop the first file onto this window. Then press [ENTER]
set /p file1=
echo Drag and drop the second file onto this window. Then press [ENTER]
set /p file2=
"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe" /diff %file1% %file2%