Skip to content

Add APIs to support .NET generic host #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: add-di-apis
Choose a base branch
from

Conversation

smdn
Copy link
Owner

@smdn smdn commented Apr 27, 2025

Description

Add support for building Munin-Node hosted service integrated with the .NET generic host.

This PR adds a new package/assembly/namespace Smdn.Net.MuninNode.Hosting.

In this PR, the following key API will be added:

  • AddHostedMuninNodeService(): An extension method to IServiceCollection to register MuninNodeBackgroundService, as described below, which runs Munin-Node as a hosted/background service. The service to be registered is configured using the APIs from Smdn.Net.MuninNode.DependencyInjection. See Add APIs to support dependency injection #17 for detail.
  • MuninNodeBackgroundService: The class extends BackgroundService to run Munin-Node as a hosted/background service. It holds a configured and built IMuninNode, and calls IMuninNode.RunAsync to start Munin-Node background tasks.

An example of using the API to be added is as follows:

var builder = Host.CreateApplicationBuilder(args);

builder.Services.AddHostedMuninNodeService(
  options => {
    options.HostName = "munin-node.localhost";
    options.UseAnyAddress(port: 12345);
    options.AllowFrom([IPAddress.Parse("192.168.2.0"), IPAddress.Loopback]);
  },
  nodeBuilder => nodeBuilder
    .AddPlugin(PluginFactory.CreatePlugin(...))
    .AddPlugin(serviceProvider => PluginFactory.CreatePlugin(...))
    .UseSessionCallback((INodeSessionCallback)new(...))
    .UseListenerFactory((IMuninNodeListenerFactory)new(...))
);

Considerations

It is noted that the implementation to be added with this PR is based on ideas proposed in the discussion #11 and PR #12.

This PR is based on #17. It needs to be merged.

@smdn smdn mentioned this pull request Apr 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant