Skip to content

Commit

Permalink
Add support for Dependency Injection with IMemoryDb (#520)
Browse files Browse the repository at this point in the history
## Motivation and Context (Why the change? What's the scenario?)

Allow to inject IMemoryDb types, without the need to build an instance.

Related to #503, it
allows to register an `IMemoryDb` using Dependency Injection.
  • Loading branch information
marcominerva authored May 27, 2024
1 parent 17d73e0 commit 2e80e90
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions service/Abstractions/KernelMemoryBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ public static IKernelMemoryBuilder WithCustomMemoryDb(
return builder;
}

public static IKernelMemoryBuilder WithCustomMemoryDb<T>(
this IKernelMemoryBuilder builder) where T : class, IMemoryDb
{
builder.AddSingleton<IMemoryDb, T>();
return builder;
}

public static IKernelMemoryBuilder WithCustomTextGenerator(
this IKernelMemoryBuilder builder,
ITextGenerator service)
Expand Down

0 comments on commit 2e80e90

Please sign in to comment.