Created
January 6, 2020 13:43
-
-
Save merken/2c0baa731ec6cbb542a727aac7910cb0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using Microsoft.AspNetCore.Http; | |
using Prise.AssemblyScanning; | |
using Prise.Infrastructure; | |
namespace Products.API.Infrastructure | |
{ | |
public class TenantAssemblySelector<T> : | |
IAssemblySelector<T> | |
{ | |
protected readonly IHttpContextAccessor contextAccessor; | |
protected readonly TenantConfig tenantConfig; | |
public TenantAssemblySelector(IHttpContextAccessor contextAccessor, TenantConfig tenantConfig) | |
{ | |
this.tenantConfig = tenantConfig; | |
this.contextAccessor = contextAccessor; | |
} | |
public IEnumerable<AssemblyScanResult<T>> SelectAssemblies(IEnumerable<AssemblyScanResult<T>> scanResults) | |
{ | |
var assemblyName = "OldSQLPlugin"; | |
if (this.contextAccessor.HttpContext.Request.Headers["Tenant"].Any()) | |
{ | |
var tenant = this.contextAccessor.HttpContext.Request.Headers["Tenant"].First(); | |
var configPair = this.tenantConfig.Configuration | |
.FirstOrDefault(c => String.Compare(c.Tenant, tenant, StringComparison.OrdinalIgnoreCase) == 0); | |
assemblyName = configPair.Plugin; | |
} | |
return scanResults.Where(a => a.PluginType.Assembly.GetName().Name == assemblyName); | |
} | |
#region IDisposable Support | |
private bool disposedValue = false; // To detect redundant calls | |
protected virtual void Dispose(bool disposing) | |
{ | |
if (!disposedValue) | |
{ | |
if (disposing) | |
{ | |
// TODO: dispose managed state (managed objects). | |
} | |
disposedValue = true; | |
} | |
} | |
public void Dispose() | |
{ | |
Dispose(true); | |
} | |
#endregion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment