それぞれの顧客が自分のDBを持っている場合があります。これは自動的に行われます。たとえば、Autofacがコントローラを作成するときです。 clientIdをして、次の文字列ASP.NET MVC 3または4 - 多くのDBを扱う方法
public class ModuleContextProvider : IModuleContextProvider
{
IModuleContext context;
public IModuleContext GetContext(int moduleId)
{
if (context == null)
{
//get module.
var rep = DependencyResolver.Current.GetService<IModuleRepository>();
var module = rep.GetById(moduleId);
context = GetContext(module);
}
return context;
}
public IModuleContext GetContext(Model.Module module)
{
if (context == null)
{
//get module.
var rep = DependencyResolver.Current.GetService<IModuleRepository>();
context = new ModuleContext(module.DBConnection);
if (context == null)
throw new InvalidOperationException("Could nto create DB COntext");
}
return context;
}
}
が、どのように私は誰もがそれについてたびに心配する必要はありませんので、私は以下のが、明らかにしているコントローラにそれを得るかを取得し、接続文字列に
を取得repositryを作成するには、私はコンテキストが必要です。
public CategoryController(ICommandBus commandBus, ICategoryRepository categoryRepository)
{
this.commandBus = commandBus;
this.categoryRepository = categoryRepository;
}
例:// Controller/ModuleId/Methodを使用して、これをUrlから取得することはできますか?
ご協力いただきありがとうございます。
編集:ここで私が考えるのは、接続文字列を(この場合はモジュールの形式で)押し続ける方法です。
を次のようにコントローラで取得します。使用する接続文字列を指定するために、moduleIdのようなものが必要です。したがって、私が見ることができるオプションは –
です。1 URLに値を持つ「モジュール」をどこかにルーティングして抽出します。これを抽出する方法がわかりません。 2.それをURL上のパラメータとして渡します。再び上のファクトリに渡す方法がわかりません。3.セッション状態を導入します。4.すべてのメソッド呼び出しでそれを渡します(非常に醜い) –