ServiceStack ORMLite で Ninject を使用したいのですが、設定方法がわかりません。
リポジトリには次のものがあります。
private readonly IDbConnectionFactory _dbFactory;
public TaskRepository(IDbConnectionFactory dbFactory)
{
_dbFactory = dbFactory;
}
public IEnumerable<Task> GetAll()
{
using (IDbConnection _db = _dbFactory.OpenDbConnection())
{
return _db.Select<Task>();
}
}
接続文字列を使用するために登録する方法がわかりません。OrmLiteConnectionFactory
私はそうするIDbConnectionFactory
ようにバインドされています:
kernel.Bind<IDbConnectionFactory>().To<OrmLiteConnectionFactory>().InScope(x => x.Request);
次のようOrmLiteConnectionFactory
に、Configure
メソッド内の新しいインスタンスも作成しました。AppHost
var ormLite = new OrmLiteConnectionFactory(
ConfigurationManager.ConnectionStrings["DefaultConnection"]
.ConnectionString, SqlServerDialect.Provider);
しかし、サービスを使用しようとすると、次のようになります。ConnectionString must be set
編集
登録方法は次のOrmLiteConnectionFactory
とおりです。
内部Configure
には次のものがあります。
var ormLite = new OrmLiteConnectionFactory(
ConfigurationManager.ConnectionStrings["AngularApp"]
.ConnectionString, SqlServerDialect.Provider);
// Create Tables and Seed Data
CreateSeedData(ormLite);
IKernel kernel = new StandardKernel();
// Register dependencies in method
RegisterDependencies(kernel);
RegisterDependencies
次のようになります。
private void RegisterDependencies(IKernel kernel)
{
kernel.Bind<IDbConnectionFactory>().To<OrmLiteConnectionFactory>()
.InSingletonScope();
kernel.Bind<ITaskRepository>().To<TaskRepository>();
}