SimpleInjector 3 sees registration as transient, even with `RegisterSingleton ()`

I am building an application (Xamarin.Forms, PCL and iOS, if it matters) that uses SimpleInjector to inject dependencies in everything. It has been great work so far, and with the recent release of SimpleInjector 3, I am updating my code to work with the new API. Unfortunately, I have a small problem with one specific registration.

Here's the main thread:

  • register ISQLitePlatform(Windows, iOS, Android, etc.) to process platform-specific bits (SQLite API, file I / O, etc.).
  • register a bootloader that will be responsible for creating the database file, setting up all table / type mappings, etc.
  • register the lambda that will create our data access provider, use the bootloader to configure the database and return the access provider

The application can then use the data access provider to open transactions in the database. The interface IDataAccessProviderhas only one method, NewTransaction()which returns an object with unit working units using common CRUD methods. IDataAccessProvideralso implements IDisposable, and methods Dispose()handle cleaning, closing open connections / transactions, etc.

The problem is with these registrations:

container.RegisterSingleton<ISQLitePlatform, SQLitePlatformIOS>();
container.RegisterSingleton<ILocalDataBootstrapper, SQLiteDataBootstrapper>();
container.RegisterSingleton<IDataAccessProvider>(
    () => container.GetInstance<ILocalDataBootstrapper>().DataAccessProvider);

- , SQLiteDataAccessProvider IDisposable . - , , , , RegisterSingleton().

RegisterSingleton() ? ? , ?

+4
1

, , , - :

container.GetInstance<SQLiteDataAccessProvider>();

, , ( ).

SQLiteDataAccessProvider "" ( IDataAccessProvider), Simple Injector , Simple Injector .

, Simple Injector; . IDataAccessProvider singleton SQLiteDataAccessProvider.

, SQLiteDataAccessProvider , Simple Injector , .

, GetInstance<SQLiteDataAccessProvider>() ( ctor ) GetInstance<IDataAccessProvider>().

+3

All Articles