Method GetService
GetService<T>()
Resolves and returns a service of the specified type from the Unity container.
Declaration
T GetService<T>()
Returns
Type | Description |
---|---|
T | The resolved service instance of type T. |
Type Parameters
Name | Description |
---|---|
T | The type of the service to resolve. |
Remarks
This method attempts to resolve a service of type T from the configured Unity container. If the service implements IDisposable, it is automatically added to a CompositeDisposable to ensure it is disposed of when the sandbox is disposed. This management of disposable resources helps in preventing memory leaks and other resource management issues.
GetService<TOut, TIn1>(TIn1)
Resolves a factory service that requires one input parameter, then creates and returns an instance of the specified type.
Declaration
TOut GetService<TOut, TIn1>(TIn1 param1)
Parameters
Type | Name | Description |
---|---|---|
TIn1 | param1 | The first parameter to pass to the factory's creation method. |
Returns
Type | Description |
---|---|
TOut | The created service instance of type TOut. |
Type Parameters
Name | Description |
---|---|
TOut | The type of the service to resolve and create. |
TIn1 | The type of the first parameter required by the factory. |
Remarks
This method is useful for resolving services that require additional configuration or parameters upon creation, as it uses a factory pattern to initialize the service instance with the specified parameter.
GetService<TOut, TIn1, TIn2>(TIn1, TIn2)
Resolves a factory service that requires two input parameters, then creates and returns an instance of the specified type.
Declaration
TOut GetService<TOut, TIn1, TIn2>(TIn1 param1, TIn2 param2)
Parameters
Type | Name | Description |
---|---|---|
TIn1 | param1 | The first parameter to pass to the factory's creation method. |
TIn2 | param2 | The second parameter to pass to the factory's creation method. |
Returns
Type | Description |
---|---|
TOut | The created service instance of type TOut. |
Type Parameters
Name | Description |
---|---|
TOut | The type of the service to resolve and create. |
TIn1 | The type of the first parameter required by the factory. |
TIn2 | The type of the second parameter required by the factory. |
Remarks
This method extends the factory pattern to services that require two parameters upon instantiation, ensuring flexibility in configuring services with multiple dependencies.
GetService<TOut, TIn1, TIn2, TIn3>(TIn1, TIn2, TIn3)
Resolves a factory service that requires three input parameters, then creates and returns an instance of the specified type.
Declaration
TOut GetService<TOut, TIn1, TIn2, TIn3>(TIn1 param1, TIn2 param2, TIn3 param3)
Parameters
Type | Name | Description |
---|---|---|
TIn1 | param1 | The first parameter to pass to the factory's creation method. |
TIn2 | param2 | The second parameter to pass to the factory's creation method. |
TIn3 | param3 | The third parameter to pass to the factory's creation method. |
Returns
Type | Description |
---|---|
TOut | The created service instance of type TOut. |
Type Parameters
Name | Description |
---|---|
TOut | The type of the service to resolve and create. |
TIn1 | The type of the first parameter required by the factory. |
TIn2 | The type of the second parameter required by the factory. |
TIn3 | The type of the third parameter required by the factory. |
Remarks
This overload supports service creation scenarios requiring three parameters, facilitating complex configuration or initialization through the factory.
GetService<TOut, TIn1, TIn2, TIn3, TIn4>(TIn1, TIn2, TIn3, TIn4)
Resolves a factory service that requires four input parameters, then creates and returns an instance of the specified type.
Declaration
TOut GetService<TOut, TIn1, TIn2, TIn3, TIn4>(TIn1 param1, TIn2 param2, TIn3 param3, TIn4 param4)
Parameters
Type | Name | Description |
---|---|---|
TIn1 | param1 | The first parameter to pass to the factory's creation method. |
TIn2 | param2 | The second parameter to pass to the factory's creation method. |
TIn3 | param3 | The third parameter to pass to the factory's creation method. |
TIn4 | param4 | The fourth parameter to pass to the factory's creation method. |
Returns
Type | Description |
---|---|
TOut | The created service instance of type TOut. |
Type Parameters
Name | Description |
---|---|
TOut | The type of the service to resolve and create. |
TIn1 | The type of the first parameter required by the factory. |
TIn2 | The type of the second parameter required by the factory. |
TIn3 | The type of the third parameter required by the factory. |
TIn4 | The type of the fourth parameter required by the factory. |
Remarks
This overload provides the most flexibility by enabling services to be created with up to four dependencies, useful for scenarios where complex initialization is necessary.