我使用SQLite,讓通過它通過在標準的方式來實現ISQLite接口[裝配:依賴(typeof運算(SQLite_iOS))] ...棱鏡Xamarin 6.2 IDependencyService服務
而且我正在努力通過Repository模式實現數據訪問模型
我BaseRepository類看起來像這樣
public abstract class BaseRepository<TEntity, TKey> : IRepository<TEntity, TKey> where TEntity : class, new()
{
private readonly SQLiteAsyncConnection _connection;
protected BaseRepository(ISQLite sqlite)
{
_connection = sqlite.GetAsyncConnection();
_connection.CreateTableAsync<TEntity>().Wait();
}
對於每個模型我有BaseRepository類的實現
public class SectorsRepository : BaseRepository<Sectors, int>, ISectorsRepository
{
public SectorsRepository(ISQLite context)
: base(context)
{
}
}
我現在正在努力如何註冊每個存儲庫類。顯然,這不起作用,因爲我沒有一個dependencyService的實例;
protected override void RegisterTypes()
{
Container.RegisterType<ISectorsRepository, SectorsRepository>(new InjectionConstructor(dependencyService.Get<ISQLite>()));
}
任何想法?
謝謝
謝謝!不知道棱鏡自動解決它們。最後,我的代碼轉換爲: Container.RegisterType(); –
James