Skip to content
Discussion options

You must be logged in to vote

This doesn't work

public class StartupCommand : ExternalCommand
{
    private readonly ILogger<StartupCommand> _logger = Host.GetService<ILogger<StartupCommand>>();
    private readonly IServiceDemo _serviceDemo = Host.GetService<IServiceDemo>();

    public override void Execute()
    {
        _serviceDemo.DoSomething();
        _logger.LogInformation("Executing the StartupCommand");
    }
}

This does work

public class StartupCommand : ExternalCommand
{
    private ILogger<StartupCommand> _logger;
    private IServiceDemo _serviceDemo;

    public override void Execute()
    {
        _logger = Host.GetService<ILogger<StartupCommand>>();
        _serviceDemo = Host.GetService<IServiceD…

Replies: 5 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@russgreen
Comment options

@Nice3point
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@Nice3point
Comment options

Answer selected by russgreen
Comment options

You must be logged in to vote
1 reply
@Nice3point
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants