Skip to content

How to integrate with .NET Generic Host? #380

Answered by thoemmi
gitfool asked this question in Q&A
Discussion options

You must be logged in to vote

@gitfool That's not crazy, I'm using the generic host with Spectre CLI too. In fact, it's already possible. The example Injection shows how to use IServiceCollection: implement your own ITypeRegistrar and ITypeResolver, and Spectre will register your commands in the IServiceCollection automatically.

In my application I have changed the implementation of ITypeRegistrar and ITypeResolver for better support of the generic host:

public sealed class TypeRegistrar : ITypeRegistrar
{
   private readonly IHostBuilder _builder;

   public TypeRegistrar(IHostBuilder builder)
   {
      _builder = builder;
   }

   public ITypeResolver Build()
   {
      return new TypeResolver(_builder.Build());
   }

Replies: 2 comments 9 replies

Comment options

You must be logged in to vote
4 replies
@gitfool
Comment options

@gitfool
Comment options

@stephen776
Comment options

@MrHinsh
Comment options

Answer selected by gitfool
Comment options

You must be logged in to vote
5 replies
@gitfool
Comment options

@jouniheikniemi
Comment options

@patriksvensson
Comment options

@jouniheikniemi
Comment options

@WurliMonkhaven
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
8 participants