Interface ISilverbackContext
Used to persist objects that are valid within the same DI scope. This is used, for example, to share the storage transaction.
Namespace: Silverback
Assembly: Silverback.Core.dll
Syntax
public interface ISilverbackContext
Properties
ServiceProvider
Gets the IServiceProvider used in the current scope.
Declaration
IServiceProvider ServiceProvider { get; }
Property Value
| Type | Description |
|---|---|
| IServiceProvider |
Methods
AddObject(Guid, object)
Stores the specified object. It will throw if an object with the same type id is already stored.
Declaration
void AddObject(Guid objectTypeId, object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | objectTypeId | A unique identifier for the object type. |
| object | obj | The object. |
GetObject(Guid)
Returns the object with the specified type id.
Declaration
object GetObject(Guid objectTypeId)
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | objectTypeId | A unique identifier for the object type. |
Returns
| Type | Description |
|---|---|
| object | A value indicating whether the transaction was found. |
GetObject<T>(Guid)
Returns the object with the specified type id.
Declaration
T GetObject<T>(Guid objectTypeId)
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | objectTypeId | A unique identifier for the object type. |
Returns
| Type | Description |
|---|---|
| T | A value indicating whether the transaction was found. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the object. |
GetOrAddObject<T>(Guid, Func<T>)
Returns the object with the specified type id or adds a new one if not found.
Declaration
T GetOrAddObject<T>(Guid objectTypeId, Func<T> factory)
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | objectTypeId | A unique identifier for the object type. |
| Func<T> | factory | The factory to create the object if not found. |
Returns
| Type | Description |
|---|---|
| T | The object. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the object. |
GetOrAddObject<TObject, TArg>(Guid, Func<TArg, TObject>, TArg)
Returns the object with the specified type id or adds a new one if not found.
Declaration
TObject GetOrAddObject<TObject, TArg>(Guid objectTypeId, Func<TArg, TObject> factory, TArg argument)
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | objectTypeId | A unique identifier for the object type. |
| Func<TArg, TObject> | factory | The factory to create the object if not found. |
| TArg | argument | The argument to pass to the factory. |
Returns
| Type | Description |
|---|---|
| TObject | The object. |
Type Parameters
| Name | Description |
|---|---|
| TObject | The type of the object. |
| TArg | The type of the argument to pass to the factory. |
RemoveObject(Guid)
Removes the object with the specified type id.
Declaration
bool RemoveObject(Guid objectTypeId)
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | objectTypeId | A unique identifier for the object type. |
Returns
| Type | Description |
|---|---|
| bool | A value indicating whether the object was found and removed. |
SetObject(Guid, object)
Stores the specified object. If an object with the same type id is already stored, it will be replaced.
Declaration
void SetObject(Guid objectTypeId, object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | objectTypeId | A unique identifier for the object type. |
| object | obj | The object. |
TryGetObject(Guid, out object?)
Checks whether an object is set for the specified type and returns it.
Declaration
bool TryGetObject(Guid objectTypeId, out object? obj)
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | objectTypeId | A unique identifier for the object type. |
| object | obj | The object. |
Returns
| Type | Description |
|---|---|
| bool | A value indicating whether the transaction was found. |
TryGetObject<T>(Guid, out T?)
Checks whether an object is set for the specified type and returns it.
Declaration
bool TryGetObject<T>(Guid objectTypeId, out T? obj)
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | objectTypeId | A unique identifier for the object type. |
| T | obj | The object. |
Returns
| Type | Description |
|---|---|
| bool | A value indicating whether the transaction was found. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the object. |