Replies: 8 comments 3 replies
-
Thank you for using my library and offering to contribute! What are your ideas/plans for integrating with .NET Generic Host? If the change can be accomplished by adding some features or APIs, this type of change can be accepted via the pull request. In any case, please let me know what kind of functionality is currently missing, or what kind of functionality you would like to add. (Please note that I'm writing in English with the help of machine translation. So the discussion may not be well done.) |
Beta Was this translation helpful? Give feedback.
-
Configuration could be standardized public interface IMnuninConfiguration
{
public int Port { get; init; }
public string Hostname { get; init; }
IReadOnlyList<IPAddress>? AllowFrom { get; init; }
} Utility function could be defined in interfaces public interface ISocketCreator
{
Socket CreateServerSocket();
}
public interface IMuninNode
{
Task RunAsync(bool throwIfCancellationRequested, CancellationToken stoppingToken);
} Static method (Node.Create) could be remove public sealed class MuninNode : NodeBase, IMuninNode
{
private IMnuninConfiguration Config { get; init; }
private ISocketCreator SocketServer { get; init; }
public override IPluginProvider PluginProvider { get; }
public override string HostName { get; }
public MuninNode(
ILogger<MuninNode> logger,
IAccessRule accessRule,
IMnuninConfiguration config,
IPluginProvider plugins,
ISocketCreator socketServer
) : base(accessRule, logger)
{
Config = config;
PluginProvider = plugins;
SocketServer = socketServer;
HostName = config.Hostname;
}
protected override Socket CreateServerSocket()
{
return SocketServer.CreateServerSocket();
}
public async Task RunAsync(bool throwIfCancellationRequested, CancellationToken stoppingToken)
{
await AcceptAsync(throwIfCancellationRequested, stoppingToken);
}
} Then IMuninNode could be used as a standard interface to create nodes public sealed class Muninservice : BackgroundService
{
private readonly ILogger<Muninservice> Logger;
private readonly IMuninNode Node;
public Muninservice(
ILogger<Muninservice> logger,
IMuninNode node
)
{
Logger = logger;
Node = node;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
Logger.LogInformation("ExecuteAsync");
await Node.RunAsync(throwIfCancellationRequested: false, stoppingToken);
Logger.LogInformation("ExecuteAsync Ended");
}
} And finaly could be used in .NET Generic Host : var builder = WebApplication.CreateBuilder(args); // or console app
builder.Services
.AddHostedService<Muninservice>()
;
To sum up, the changes would be :
|
Beta Was this translation helpful? Give feedback.
-
Thank you for suggesting a great idea! I would like to make the changes in the following three steps. This means that the changes will be made with the three pull requests.
In each of these steps, we will perform the tasks listed below.
If this is OK with you, let's continue the discussion. |
Beta Was this translation helpful? Give feedback.
-
Started a PR #11 so we can start discussing the implementation |
Beta Was this translation helpful? Give feedback.
-
IMuninConfigurationComment about IMnuninConfiguration: public interface IMnuninConfiguration
{
public int Port { get; init; }
public string Hostname { get; init; }
IReadOnlyList<IPAddress>? AllowFrom { get; init; }
}
I suggest the following code for the reasons I mentioned above. namespace Smdn.Net.MuninNode;
public interface IMuninNodeConfiguration
{
int Port { get; }
IPAddress Address { get; }
string HostName { get; }
IReadOnlyList<IPAddress>? AllowFrom { get; }
} |
Beta Was this translation helpful? Give feedback.
-
IMuninNodepublic interface IMuninNode
{
Task RunAsync(bool throwIfCancellationRequested, CancellationToken stoppingToken);
} I have no particular opinion on this. We can just decide on the namespace. namespace Smdn.Net.MuninNode;
public interface IMuninNode
{
Task RunAsync(bool throwIfCancellationRequested, CancellationToken stoppingToken);
} That's all for today. I will comment on other interfaces tomorrow. |
Beta Was this translation helpful? Give feedback.
-
In PR #16, I added an I will continue to add support for dependency injection and .NET generic host. |
Beta Was this translation helpful? Give feedback.
-
I have implemented new features based on the ideas you have proposed, and released the following package. Thank you for proposing the idea! With this change, See the release notes above for more details, including API changes. Also, this discussion will be considered complete and closed. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
First of all, thank you for your work on this library — it’s been really helpful. I’m currently exploring ways to adapt it to work seamlessly with the .NET Generic Host model introduced in .NET Core and later.
Would you be open to discussing how this integration could be done? I’d be happy to contribute or collaborate on a possible update if you’re interested.
Beta Was this translation helpful? Give feedback.
All reactions