Skip to content

Commit 2e80e90

Browse files
authored
Add support for Dependency Injection with IMemoryDb (#520)
## 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.
1 parent 17d73e0 commit 2e80e90

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

service/Abstractions/KernelMemoryBuilderExtensions.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,13 @@ public static IKernelMemoryBuilder WithCustomMemoryDb(
165165
return builder;
166166
}
167167

168+
public static IKernelMemoryBuilder WithCustomMemoryDb<T>(
169+
this IKernelMemoryBuilder builder) where T : class, IMemoryDb
170+
{
171+
builder.AddSingleton<IMemoryDb, T>();
172+
return builder;
173+
}
174+
168175
public static IKernelMemoryBuilder WithCustomTextGenerator(
169176
this IKernelMemoryBuilder builder,
170177
ITextGenerator service)

0 commit comments

Comments
 (0)