Table of Contents

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

IServiceProvider

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

objectTypeId Guid

A unique identifier for the object type.

obj object

The object.

GetObject(Guid)

Returns the object with the specified type id.

object GetObject(Guid objectTypeId)

Parameters

objectTypeId Guid

A 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

objectTypeId Guid

A unique identifier for the object type.

Returns

T

A value indicating whether the transaction was found.

Type Parameters

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.

T GetOrAddObject<T>(Guid objectTypeId, Func<T> factory)

Parameters

objectTypeId Guid

A unique identifier for the object type.

factory Func<T>

The factory to create the object if not found.

Returns

T

The object.

Type Parameters

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.

TObject GetOrAddObject<TObject, TArg>(Guid objectTypeId, Func<TArg, TObject> factory, TArg argument)

Parameters

objectTypeId Guid

A unique identifier for the object type.

factory Func<TArg, TObject>

The factory to create the object if not found.

argument TArg

The argument to pass to the factory.

Returns

TObject

The object.

Type Parameters

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.

bool RemoveObject(Guid objectTypeId)

Parameters

objectTypeId Guid

A 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

objectTypeId Guid

A unique identifier for the object type.

obj object

The object.

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

objectTypeId Guid

A unique identifier for the object type.

obj object

The object.

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

objectTypeId Guid

A unique identifier for the object type.

obj T

The object.

Returns

bool

A value indicating whether the transaction was found.

Type Parameters

T

The type of the object.