UnityContainer.RegisterInstance Method
RegisterType an instance with the container.
Namespace: Microsoft.Practices.Unity
Assembly: Microsoft.Practices.Unity (in Microsoft.Practices.Unity.dll)
Syntax
'Declaration
Public Function RegisterInstance ( _
t As Type, _
name As String, _
instance As Object, _
lifetime As LifetimeManager _
) As IUnityContainer
public IUnityContainer RegisterInstance(
Type t,
string name,
Object instance,
LifetimeManager lifetime
)
public:
virtual IUnityContainer^ RegisterInstance(
Type^ t,
String^ name,
Object^ instance,
LifetimeManager^ lifetime
) sealed
public final function RegisterInstance(
t : Type,
name : String,
instance : Object,
lifetime : LifetimeManager
) : IUnityContainer
Parameters
- t
Type: System.Type
Type of instance to register (may be an implemented interface instead of the full type).
- name
Type: System.String
Name for registration.
- instance
Type: System.Object
Object to returned.
lifetime
Type: Microsoft.Practices.Unity.LifetimeManagerIf true, the container will take over the lifetime of the instance, calling Dispose on it (if it's IDisposable) when the container is Disposed.
If false, container will not maintain a strong reference to instance. User is reponsible for disposing instance, and for keeping the instance from being garbage collected.
Return Value
The UnityContainer object that this method was called on (this in C#, Me in Visual Basic).
Implements
IUnityContainer.RegisterInstance(Type, String, Object, LifetimeManager)
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.