Class Service
This is the entry point for registering dependency injection implementation in Couchbase Lite .NET
Inheritance
Inherited Members
Namespace: Couchbase.Lite.DI
Assembly: Couchbase.Lite.dll
Syntax
public static class Service
Methods
| Improve this Doc View SourceAutoRegister(Assembly)
Automatically register all the dependency types declared CouchbaseDependencyAttributes. To auto register classes, they must implement an interface and must have a default constructor.
Declaration
public static void AutoRegister(Assembly assembly)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.Assembly | assembly |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown if |
System.InvalidOperationException | Thrown if an invalid type is found inside of the assembly (i.e. one that does not implement any interfaces and/or does not have a parameter-less constructor) |
GetInstance<T>()
Gets the implementation for the given service, or null
if no implementation is registered
Declaration
public static T GetInstance<T>()
where T : class
Returns
Type | Description |
---|---|
T | The implementation for the given service |
Type Parameters
Name | Description |
---|---|
T | The type of service to get an implementation for |
Register<TService>(TService)
Registers an instantiated object as a singleton implementation for a service
Declaration
public static void Register<TService>(TService instance)
where TService : class
Parameters
Type | Name | Description |
---|---|---|
TService | instance | The singleton instance to use as the implementation |
Type Parameters
Name | Description |
---|---|
TService | The service type |
Register<TService>(Func<TService>, Boolean)
Registers a lazy implementation for the given service
Declaration
public static void Register<TService>(Func<TService> generator, bool transient = false)
where TService : class
Parameters
Type | Name | Description |
---|---|---|
System.Func<TService> | generator | The function that creates the object to use |
System.Boolean | transient | If |
Type Parameters
Name | Description |
---|---|
TService | The service type |
Register<TService, TImplementation>(Boolean)
Registers an implementation for the given service
Declaration
public static void Register<TService, TImplementation>(bool transient = false)
where TService : class where TImplementation : class, TService
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | transient | If |
Type Parameters
Name | Description |
---|---|
TService | The service type |
TImplementation | The implementation type |