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