Dependency Injection in Process Framework #9379
Closed
abhijeetagnihotri
started this conversation in
General
Replies: 2 comments
-
the kernal has GetRequiredService so, you might be able to use that |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hi @abhijeetagnihotri, thanks for your question. Dependency injection works in the process steps as long as you have the Kernel configured with your DI, see here for an example: Additionally, if you want to configure an initial state for a stateful step, you can do that like this: var myCStep = processBuilder.AddStepFromType<CStep, CStepState>(initialState: new() { CurrentCycle = 1 }); See here: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi Team!
I am experimenting for our future product using semantic kernel process flow framework. However, I don't find a good example to inject dependencies into the process steps in process framework. Please provide an example to use the same.
For reference, Below is the structure of my code.
IKernelBuilder kernelBuilder = Kernel.CreateBuilder();
kernelBuilder.AddAzureOpenAIChatCompletion("gpt-4o", "https://.openai.azure.com", "secret");
kernelBuilder.AddAzureOpenAITextEmbeddingGeneration("text-embedding-3-large", "https://.openai.azure.com/", "secret");
kernelBuilder.Services.AddScoped(m =>
{
var embeddingService = m.GetRequiredService();
return new AzureOpenAiEmbeddingService(embeddingService);
});
Kernel kernel = kernelBuilder.Build();
ProcessBuilder processBuilder = new("CustomProcess");
//Add steps
var embeddingStep = processBuilder.AddStepFromType();
GetEmbeddingsFromTextStep.cs file has a parameterized constructor which expects a dependency to be injected.
Beta Was this translation helpful? Give feedback.
All reactions