Created
August 21, 2017 14:27
-
-
Save AlbertoMonteiro/7bff92c3d22acbe01a36704e39a51e35 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
interface IConnectionString | |
{ | |
string ObterConnectionDoClienteString(); | |
} | |
class ConnectionString : IConnectionString | |
{ | |
private Dicitionary<string, string> _connectionStrings = new Dicitionary<string, string>(); | |
public string ObterConnectionDoClienteString() | |
{ | |
var cliente = HttpContext.Current.Request.Url.SubDominio; | |
if(_connectionStrings.HasKey(cliente)) | |
return _connectionStrings[cliente]; | |
//Criar connectionstring | |
var novaConnectionStringCriada = CriarConnectionStringParaCliente(cliente); | |
//Salvar no dictionary | |
_connectionStrings.Add(cliente, novaConnectionStringCriada); | |
return novaConnectionStringCriada; | |
} | |
private string CriarConnectionStringParaCliente(string cliente) | |
{ | |
//Seu codigo | |
} | |
} | |
class ContextoDoEf : DbContext | |
{ | |
public ContextoDoEf(IConnectionString connectionString) | |
: base(connectionString.ObterConnectionDoClienteString()) | |
{ | |
} | |
} | |
class RepositorioDapper | |
{ | |
private readonly string _connectionString; | |
public RepositorioDapper(IConnectionString connectionString) | |
{ | |
_connectionString = connectionString.ObterConnectionDoClienteString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment