Show / Hide Table of Contents

Class Service

This is the entry point for registering dependency injection implementation in Couchbase Lite .NET

Inheritance
System.Object
Service
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Couchbase.Lite.DI
Assembly: Couchbase.Lite.dll
Syntax
public static class Service

Methods

| Improve this Doc View Source

AutoRegister(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 assembly is null

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)

| Improve this Doc View Source

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

| Improve this Doc View Source

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

| Improve this Doc View Source

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 true each call to GetInstance<T>() will return a new instance, otherwise use a singleton

Type Parameters
Name Description
TService

The service type

| Improve this Doc View Source

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 true each call to GetInstance<T>() will return a new instance, otherwise use a singleton

Type Parameters
Name Description
TService

The service type

TImplementation

The implementation type

  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX