Table of Contents

Class ServiceManager

Namespace
OrpheusCore
Assembly
OrpheusCore.dll

Class to register internal services needed by Orpheus. In v2.0.0+, prefer constructor injection via IServiceProvider/ILoggerFactory over the static methods. The ServiceProvider property is deprecated.

public static class ServiceManager
Inheritance
ServiceManager
Inherited Members

Properties

LoggerFactory

The ILoggerFactory resolved from ServiceProvider, cached after the first access.

public static ILoggerFactory LoggerFactory { get; }

Property Value

ILoggerFactory

ServiceProvider

The service provider used by Resolve<T>(), LoggerFactory, and the other static resolution helpers below. Must be assigned (typically right after building the service collection with BuildServiceProvider()) before calling them.

[Obsolete("Prefer constructor injection of IServiceProvider. This static property is retained for backward compatibility.")]
public static IServiceProvider ServiceProvider { get; set; }

Property Value

IServiceProvider

Methods

AddOrpheusServices(IServiceCollection)

Registers the internal services Orpheus needs at runtime: table options, module and schema types, a default IDatabaseConnectionConfiguration, and (only if nothing has registered ILoggerFactory yet) a console logger fallback. Engine-specific connection factories and DDL helpers are not registered here — use the per-engine AddOrpheusSqlServer/AddOrpheusMySql/AddOrpheusPostgreSql extension methods (which call this internally) instead of calling this directly.

public static IServiceCollection AddOrpheusServices(this IServiceCollection services)

Parameters

services IServiceCollection

The service collection to register Orpheus's services into.

Returns

IServiceCollection

The same services instance, for chaining.

CreateLogger<T>()

Creates a logger for T via LoggerFactory. Returns null if no ILoggerFactory is registered in ServiceProvider.

public static ILogger<T> CreateLogger<T>()

Returns

ILogger<T>

Type Parameters

T

GetLoggerService(Type)

Resolves an arbitrary service by type from ServiceProvider. Despite the name, this is not limited to logging-related services — it's a general-purpose lookup.

public static object GetLoggerService(Type type)

Parameters

type Type

The service type to resolve.

Returns

object

Resolve(Type, object[])

Resolves a service by type from ServiceProvider. When constructorParameters is supplied, instead of returning the DI-resolved instance directly, this looks up the resolved service's concrete type and invokes whichever of its constructors' parameter types are assignable from the supplied arguments — for constructing an instance with runtime-known arguments that aren't themselves resolvable from the container.

public static object Resolve(Type serviceType, object[] constructorParameters)

Parameters

serviceType Type

The service type to resolve.

constructorParameters object[]

Constructor arguments to invoke a matching constructor with, or null/empty to just return the DI-resolved instance.

Returns

object

Resolve<T>()

Resolves a service of type T from ServiceProvider.

public static T Resolve<T>()

Returns

T

Type Parameters

T

Resolve<T>(object[])

Generic counterpart of Resolve(Type, object[]).

public static T Resolve<T>(object[] constructorParameters)

Parameters

constructorParameters object[]

Constructor arguments to invoke a matching constructor with, or null/empty to just return the DI-resolved instance.

Returns

T

Type Parameters

T