UnityContainerExtensions.RegisterInstance Method (IUnityContainer, Type, Object)

Register an instance with the container.

Namespace:  Microsoft.Practices.Unity
Assembly:  Microsoft.Practices.Unity (in Microsoft.Practices.Unity.dll)

Syntax

'Declaration
<ExtensionAttribute> _
Public Shared Function RegisterInstance ( _
    container As IUnityContainer, _
    t As Type, _
    instance As Object _
) As IUnityContainer
public static IUnityContainer RegisterInstance(
    this IUnityContainer container,
    Type t,
    Object instance
)
[ExtensionAttribute]
public:
static IUnityContainer^ RegisterInstance(
    IUnityContainer^ container, 
    Type^ t, 
    Object^ instance
)
public static function RegisterInstance(
    container : IUnityContainer, 
    t : Type, 
    instance : Object
) : IUnityContainer

Parameters

  • t
    Type: System.Type
    Type of instance to register (may be an implemented interface instead of the full type).

Return Value

The UnityContainer object that this method was called on (this in C#, Me in Visual Basic).

Remarks

Instance registration is much like setting a type as a singleton, except that instead of the container creating the instance the first time it is requested, the user creates the instance ahead of type and adds that instance to the container.

This overload does a default registration and has the container take over the lifetime of the instance.

See Also

UnityContainerExtensions Class

RegisterInstance Overload

Microsoft.Practices.Unity Namespace