Class ServiceLocator<TContract, TSelf>
Provides a readily testable way to manage a Singleton.
Inheritance
System.Object
ServiceLocator<TContract, TSelf>
Namespace: DotNetNuke.Framework
Assembly: DotNetNuke.dll
Syntax
public abstract class ServiceLocator<TContract, TSelf> : object where TSelf : ServiceLocator<TContract, TSelf>, new()
Type Parameters
| Name | Description |
|---|---|
| TContract | The interface that the controller provides. |
| TSelf | The type of the controller itself, used to call the GetFactory override. |
Properties
| Improve this Doc View SourceFactory
Gets or sets the service locator factory.
Declaration
protected static Func<TContract> Factory { get; set; }
Property Value
| Type | Description |
|---|---|
| Func<TContract> |
Instance
Gets a singleton of T.
Declaration
public static TContract Instance { get; }
Property Value
| Type | Description |
|---|---|
| TContract |
Methods
| Improve this Doc View SourceClearInstance()
Clears the current instance, a new instance will be initialized when next requested.
Declaration
public static void ClearInstance()
Remarks
Intended for unit testing purposes, not thread safe.
GetFactory()
Gets the service locator factory.
Declaration
protected abstract Func<TContract> GetFactory()
Returns
| Type | Description |
|---|---|
| Func<TContract> | A factory function. |
SetTestableInstance(TContract)
Registers an instance to use for the Singleton.
Declaration
public static void SetTestableInstance(TContract instance)
Parameters
| Type | Name | Description |
|---|---|---|
| TContract | instance | The instance to set. |
Remarks
Intended for unit testing purposes, not thread safe.