Skip to content

[Discussion] Implement Generic Host #75

@TheBrambleShark

Description

@TheBrambleShark

A Generic Host encapsulates Dependency Injection, Logging, and Configuration in a nice, easy package.

Our current setup seems to want to achieve this but does this in a sort of homebrew way.

Changes to make to implement this:

  • Rewrite Program.cs to use a generic host
  • Services will be injected and hosted as either a singleton or in a scoped context.
  • Service and module dependencies will be injected (automatically) into the constructor.

Benefits of using a Generic Host:

  • Error handling is more intuitive
  • Scoped services can be created and destroyed as needed, proving some light scaling.
  • Resources are injected through the constructor, meaning they're easily available
  • Scoped ILogger<TService> instances
  • Configurations constructed from multiple sources, such as json configs, environment variables, or command line arguments, and injected as an IOptions<TConfiguration> object.
  • Easy implementation of libraries to assist the bot with growth, such as MediatR.

If this is something we might be interested in, I would be happy to build a PR with all of the necessary tests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions