とSQLiteAsyncConnectionのシングルトンを注入し、Iは各plateformのデータベースの場所を定義するために使用される最初のクラスがありますAutofac IはPCLとXamarinネイティブプロジェクトを行うm個のparams
public class DatabaseConfiguration : IDatabaseConfiguration
{
public string GetConnectionString()
{
//This code is specific to each platform
return PathForEachPlatform;
}
}
を私はそれを注入このように:
builder.RegisterType<DatabaseConfiguration>()
.As<IDatabaseConfiguration>()
.SingleInstance();
今、私は私のリポジトリクラスにSQLiteAsyncConnection
を注入するwan't。このクラスは、このnugetsからである。ここではhttps://www.nuget.org/packages/sqlite-net-pcl
は私のリポジトリのコンストラクタです:
private SQLiteAsyncConnection Connection { get; }
public SQLiteRepository(IDatabaseConfiguration configuration)
{
Connection = new SQLiteAsyncConnection(configuration.GetConnectionString()); // I wan't to inject the connection not create a new one.
}
}
SQLiteAsyncConnection
インターフェイスを提供していないので、私はシングルトンを使用することを決定しました。しかし、コンストラクタにはデータベースパスが必要です。このパスは、GetConnectionString()
メソッドで上記の他の注入によって定義されます。どうやってやるの ?今の
私はこのコードを持っている:
builder.RegisterInstance<SQLiteAsyncConnection>()
.WithParameter(new TypedParameter(typeof(string),"HERE THE PATH TO PASS BUT HOW ?"))
.SingleInstance();
.As()を削除するのはなぜですか?それは私のために良いloksいいえ? –
fandro
これはオプションで、そこにいる必要はありません。あなたが好きなら、あなたはそれをそこに残すことができます - それは何もしません。 – mjwills
OK、うまくいきません、私はもう少しチェックを行い、答えを検証します。 – fandro