Replies: 3 comments 4 replies
-
Hi @TamasG, "No service for type 'SampleCommandDotNetDI.App' has been registered." indicates the |
Beta Was this translation helpful? Give feedback.
-
Hello @drewburlingame, thanks for the answers, I understand your answer, but i couldn't solve it. I don't spend any more time on this, I was looking for another solution. Thanks again, Tamas |
Beta Was this translation helpful? Give feedback.
-
Hi Tomas,
The error "No service for type 'SampleCommandDotNetDI.App' has been
registered." indicates this type has not been registered with the DI
container and I do not see it being registered in the code you've posted.
…On Fri 24 Jun 2022, 03:33 Tamas, ***@***.***> wrote:
Hello,
can you help me? I read these:
https://commanddotnet.bilal-fazlani.com/otherfeatures/dependency-injection/
https://v2.commanddotnet.bilal-fazlani.com/dependency-injection/
#27 <#27>
I've been dealing with it for hours, but it doesn't work, what's wrong?
(I understand what property injection is.)
My simple code:
using CommandDotNet;using CommandDotNet.IoC.MicrosoftDependencyInjection;using Microsoft.Extensions.DependencyInjection;
namespace SampleCommandNetDI;
public class Program
{
static int Main(string[] args)
{
IServiceCollection serviceCollection = new ServiceCollection();
serviceCollection.AddSingleton<IService, Service>();
IServiceProvider serviceProvider = serviceCollection.BuildServiceProvider();
AppRunner appRunner = new AppRunner<App>()
.UseMicrosoftDependencyInjection(serviceProvider);
int exitCode = appRunner.Run(args);
Console.WriteLine("ExitCode: " + exitCode);
return exitCode;
}
}
public class App
{
public void Print()
{
Console.WriteLine(Service!.GetValue().ToString());
}
public IService? Service { get; set; }
}
public interface IService
{
int GetValue();
}
public class Service : IService
{
public int GetValue()
{
return 4;
}
}
Result:
C:\Users.....dotnet SampleCommandNetDI.dll Print
Unhandled exception. System.InvalidOperationException: No service for type
'SampleCommandDotNetDI.App' has been registered.
at
Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider
provider, Type serviceType)
at
CommandDotNet.IoC.MicrosoftDependencyInjection.MicrosoftDependencyInjectionResolver.Resolve(Type
type) in
CommandDotNet.IoC.MicrosoftDependencyInjection/MicrosoftDependencyInjectionResolver.cs:line
18
at CommandDotNet.Execution.ResolverService.ConditionalTryResolve(Type
type, Object& item, ResolveStrategy resolveStrategy) in
CommandDotNet/Execution/ResolverService.cs:line 89
at CommandDotNet.Execution.ResolverService.ResolveCommandClass(Type
classType, CommandContext commandContext) in
CommandDotNet/Execution/ResolverService.cs:line 33
at
CommandDotNet.ClassModeling.ResolveCommandClassesMiddleware.GetInstance(InvocationStep
invocationStep, InvocationStep parentStep, CommandContext commandContext)
in CommandDotNet/ClassModeling/ResolveCommandClassesMiddleware.cs:line 51
at
...
...
...
at
CommandDotNet.Execution.ExecutionMiddlewareExtensions.InvokePipeline(IEnumerable`1
pipeline, CommandContext commandContext) in
CommandDotNet/Execution/ExecutionMiddlewareExtensions.cs:line 33
at CommandDotNet.AppRunner.Run(String[] args) in
CommandDotNet/AppRunner.cs:line 89
--- End of stack trace from previous location ---
at CommandDotNet.AppRunner.HandleException(Exception ex, CommandContext
commandContext) in CommandDotNet/AppRunner.cs:line 185
at CommandDotNet.AppRunner.Run(String[] args) in
CommandDotNet/AppRunner.cs:line 95
Thanks in advance,
Tamas
—
Reply to this email directly, view it on GitHub
<#437>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAZHMLHYW3ADQM6USGMHNDVQUNA7ANCNFSM5ZWJCLBA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Hello,
can you help me? I read these:
https://commanddotnet.bilal-fazlani.com/otherfeatures/dependency-injection/
https://v2.commanddotnet.bilal-fazlani.com/dependency-injection/
#27
I've been dealing with it for hours, but it doesn't work, what's wrong?
(I understand what property injection is.)
My simple code:
Result:
C:\Users.....dotnet SampleCommandNetDI.dll Print
Unhandled exception. System.InvalidOperationException: No service for type 'SampleCommandDotNetDI.App' has been registered.
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at CommandDotNet.IoC.MicrosoftDependencyInjection.MicrosoftDependencyInjectionResolver.Resolve(Type type) in CommandDotNet.IoC.MicrosoftDependencyInjection/MicrosoftDependencyInjectionResolver.cs:line 18
at CommandDotNet.Execution.ResolverService.ConditionalTryResolve(Type type, Object& item, ResolveStrategy resolveStrategy) in CommandDotNet/Execution/ResolverService.cs:line 89
at CommandDotNet.Execution.ResolverService.ResolveCommandClass(Type classType, CommandContext commandContext) in CommandDotNet/Execution/ResolverService.cs:line 33
at CommandDotNet.ClassModeling.ResolveCommandClassesMiddleware.GetInstance(InvocationStep invocationStep, InvocationStep parentStep, CommandContext commandContext) in CommandDotNet/ClassModeling/ResolveCommandClassesMiddleware.cs:line 51
at
...
...
...
at CommandDotNet.Execution.ExecutionMiddlewareExtensions.InvokePipeline(IEnumerable`1 pipeline, CommandContext commandContext) in CommandDotNet/Execution/ExecutionMiddlewareExtensions.cs:line 33
at CommandDotNet.AppRunner.Run(String[] args) in CommandDotNet/AppRunner.cs:line 89
--- End of stack trace from previous location ---
at CommandDotNet.AppRunner.HandleException(Exception ex, CommandContext commandContext) in CommandDotNet/AppRunner.cs:line 185
at CommandDotNet.AppRunner.Run(String[] args) in CommandDotNet/AppRunner.cs:line 95
Thanks in advance,
Tamas
Beta Was this translation helpful? Give feedback.
All reactions