You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "ptupitsyn (via GitHub)" <gi...@apache.org> on 2025/12/22 13:57:08 UTC
[PR] IGNITE-27423 .NET: Set LoggerFactory automatically in IgniteServiceCollectionExtensions [ignite-3]
ptupitsyn opened a new pull request, #7277:
URL: https://github.com/apache/ignite-3/pull/7277
(no comment)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-27423 .NET: Set LoggerFactory automatically in IgniteServiceCollectionExtensions [ignite-3]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #7277:
URL: https://github.com/apache/ignite-3/pull/7277#discussion_r2639973589
##########
modules/platforms/dotnet/Apache.Ignite/IgniteServiceCollectionExtensions.cs:
##########
@@ -140,7 +142,19 @@ private static IServiceCollection AddIgniteClientGroupCore(
services.TryAdd(new ServiceDescriptor(
typeof(IgniteClientGroup),
key,
- (sp, innerKey) => new IgniteClientGroup(configure(sp, innerKey)),
+ (serviceProvider, innerKey) =>
+ {
+ IgniteClientGroupConfiguration cfg = configure(serviceProvider, innerKey);
+
+ if (cfg.ClientConfiguration.LoggerFactory == NullLoggerFactory.Instance)
+ {
+ // Use DI logger factory if none was provided.
+ cfg.ClientConfiguration.LoggerFactory =
+ serviceProvider.GetService<ILoggerFactory>() ?? NullLoggerFactory.Instance;
Review Comment:
The code modifies the LoggerFactory property of the configuration object that was passed in by the user. This mutates the original configuration, which may be unexpected behavior. Consider creating a copy of the configuration before modifying it to avoid side effects on the user's configuration object. For example, you could use the record's with expression to create a modified copy: `cfg = cfg with { ClientConfiguration = cfg.ClientConfiguration with { LoggerFactory = ... } }`.
```suggestion
var loggerFactory = serviceProvider.GetService<ILoggerFactory>() ?? NullLoggerFactory.Instance;
cfg = cfg with
{
ClientConfiguration = cfg.ClientConfiguration with
{
LoggerFactory = loggerFactory
}
};
```
##########
modules/platforms/dotnet/README.md:
##########
@@ -60,6 +60,31 @@ IJobExecution<int> jobExecution = await client.Compute.SubmitAsync(
int wordCount = await jobExecution.GetResultAsync();
```
+## DI Integration
+
+Use `IgniteServicesCollectionExtensions.AddIgniteClientGroup` to register Ignite client in the dependency injection container:
Review Comment:
The class name has a typo. It should be "IgniteServiceCollectionExtensions" not "IgniteServicesCollectionExtensions" (remove the extra 's' in "Services").
```suggestion
Use `IgniteServiceCollectionExtensions.AddIgniteClientGroup` to register Ignite client in the dependency injection container:
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-27423 .NET: Set LoggerFactory automatically in IgniteServiceCollectionExtensions [ignite-3]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #7277:
URL: https://github.com/apache/ignite-3/pull/7277#discussion_r2640020254
##########
modules/platforms/dotnet/Apache.Ignite.Tests/IgniteServiceCollectionExtensionsTests.cs:
##########
@@ -153,6 +153,55 @@ public void TestRegisterScopesConfigurationFuncWithKeyKeyed([Values] ServiceLife
(s, key) => s.AddIgniteClientGroupKeyed(key, (_, _) => CreateGroupConfig(), lifetime));
}
+ [Test]
+ public void TestAutomaticLoggerFactorySetFromServices()
+ {
+ var services = new ServiceCollection();
+
+ var diLoggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
Review Comment:
The ILoggerFactory created here should be disposed to prevent resource leaks. ILoggerFactory implements IDisposable, and the logger factory should be disposed after the test completes. Consider wrapping it in a using statement or disposing it explicitly at the end of the test.
```suggestion
using var diLoggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
```
##########
modules/platforms/dotnet/Apache.Ignite.Tests/IgniteServiceCollectionExtensionsTests.cs:
##########
@@ -153,6 +153,55 @@ public void TestRegisterScopesConfigurationFuncWithKeyKeyed([Values] ServiceLife
(s, key) => s.AddIgniteClientGroupKeyed(key, (_, _) => CreateGroupConfig(), lifetime));
}
+ [Test]
+ public void TestAutomaticLoggerFactorySetFromServices()
+ {
+ var services = new ServiceCollection();
+
+ var diLoggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
+ services.AddSingleton(diLoggerFactory);
+
+ var config = new IgniteClientGroupConfiguration
+ {
+ ClientConfiguration = new IgniteClientConfiguration(_server.Endpoint)
+ };
+
+ services.AddIgniteClientGroup(config);
+
+ using var serviceProvider = services.BuildServiceProvider();
+ using var group = serviceProvider.GetRequiredService<IgniteClientGroup>();
+
+ var actualLoggerFactory = group.Configuration.ClientConfiguration.LoggerFactory;
+ Assert.AreSame(diLoggerFactory, actualLoggerFactory);
+ }
Review Comment:
The automatic LoggerFactory injection feature lacks test coverage for Func-based registration methods. Consider adding tests for AddIgniteClientGroup with Func<IServiceProvider, IgniteClientGroupConfiguration> to ensure the automatic logger factory injection works correctly when configurations are created dynamically from the service provider.
##########
modules/platforms/dotnet/Apache.Ignite.Tests/IgniteServiceCollectionExtensionsTests.cs:
##########
@@ -153,6 +153,55 @@ public void TestRegisterScopesConfigurationFuncWithKeyKeyed([Values] ServiceLife
(s, key) => s.AddIgniteClientGroupKeyed(key, (_, _) => CreateGroupConfig(), lifetime));
}
+ [Test]
+ public void TestAutomaticLoggerFactorySetFromServices()
+ {
+ var services = new ServiceCollection();
+
+ var diLoggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
+ services.AddSingleton(diLoggerFactory);
+
+ var config = new IgniteClientGroupConfiguration
+ {
+ ClientConfiguration = new IgniteClientConfiguration(_server.Endpoint)
+ };
+
+ services.AddIgniteClientGroup(config);
+
+ using var serviceProvider = services.BuildServiceProvider();
+ using var group = serviceProvider.GetRequiredService<IgniteClientGroup>();
+
+ var actualLoggerFactory = group.Configuration.ClientConfiguration.LoggerFactory;
+ Assert.AreSame(diLoggerFactory, actualLoggerFactory);
+ }
+
+ [Test]
+ public void TestCustomLoggerFactoryIsPreserved()
+ {
+ var services = new ServiceCollection();
+
+ var diLoggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
+ services.AddSingleton(diLoggerFactory);
+
+ var customLoggerFactory = TestUtils.GetConsoleLoggerFactory(LogLevel.Trace);
+ var config = new IgniteClientGroupConfiguration
+ {
+ ClientConfiguration = new IgniteClientConfiguration(_server.Endpoint)
+ {
+ LoggerFactory = customLoggerFactory
+ }
+ };
+
+ services.AddIgniteClientGroup(config);
+
+ using var serviceProvider = services.BuildServiceProvider();
+ using var group = serviceProvider.GetRequiredService<IgniteClientGroup>();
+
+ var actualLoggerFactory = group.Configuration.ClientConfiguration.LoggerFactory;
+ Assert.AreSame(customLoggerFactory, actualLoggerFactory);
+ Assert.AreNotSame(diLoggerFactory, actualLoggerFactory);
+ }
Review Comment:
The automatic LoggerFactory injection feature lacks test coverage for keyed service registration methods. Consider adding tests for AddIgniteClientGroupKeyed to ensure the automatic logger factory injection works correctly when using service keys.
##########
modules/platforms/dotnet/Apache.Ignite.Tests/IgniteServiceCollectionExtensionsTests.cs:
##########
@@ -153,6 +153,55 @@ public void TestRegisterScopesConfigurationFuncWithKeyKeyed([Values] ServiceLife
(s, key) => s.AddIgniteClientGroupKeyed(key, (_, _) => CreateGroupConfig(), lifetime));
}
+ [Test]
+ public void TestAutomaticLoggerFactorySetFromServices()
+ {
+ var services = new ServiceCollection();
+
+ var diLoggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
+ services.AddSingleton(diLoggerFactory);
+
+ var config = new IgniteClientGroupConfiguration
+ {
+ ClientConfiguration = new IgniteClientConfiguration(_server.Endpoint)
+ };
+
+ services.AddIgniteClientGroup(config);
+
+ using var serviceProvider = services.BuildServiceProvider();
+ using var group = serviceProvider.GetRequiredService<IgniteClientGroup>();
+
+ var actualLoggerFactory = group.Configuration.ClientConfiguration.LoggerFactory;
+ Assert.AreSame(diLoggerFactory, actualLoggerFactory);
+ }
+
+ [Test]
+ public void TestCustomLoggerFactoryIsPreserved()
+ {
+ var services = new ServiceCollection();
+
+ var diLoggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
+ services.AddSingleton(diLoggerFactory);
+
+ var customLoggerFactory = TestUtils.GetConsoleLoggerFactory(LogLevel.Trace);
Review Comment:
The ILoggerFactory created here should be disposed to prevent resource leaks. ILoggerFactory implements IDisposable, and both logger factories should be disposed after the test completes. Consider wrapping them in using statements or disposing them explicitly at the end of the test.
```suggestion
using var customLoggerFactory = TestUtils.GetConsoleLoggerFactory(LogLevel.Trace);
var services = new ServiceCollection();
var diLoggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
services.AddSingleton(diLoggerFactory);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-27423 .NET: Set LoggerFactory automatically in IgniteServiceCollectionExtensions [ignite-3]
Posted by "gurustron (via GitHub)" <gi...@apache.org>.
gurustron commented on code in PR #7277:
URL: https://github.com/apache/ignite-3/pull/7277#discussion_r2639979855
##########
modules/platforms/dotnet/README.md:
##########
@@ -60,6 +60,31 @@ IJobExecution<int> jobExecution = await client.Compute.SubmitAsync(
int wordCount = await jobExecution.GetResultAsync();
```
+## DI Integration
+
+Use `IgniteServicesCollectionExtensions.AddIgniteClientGroup` to register Ignite client in the dependency injection container:
Review Comment:
He seems to be right here)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-27423 .NET: Set LoggerFactory automatically in IgniteServiceCollectionExtensions [ignite-3]
Posted by "ptupitsyn (via GitHub)" <gi...@apache.org>.
ptupitsyn merged PR #7277:
URL: https://github.com/apache/ignite-3/pull/7277
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-27423 .NET: Set LoggerFactory automatically in IgniteServiceCollectionExtensions [ignite-3]
Posted by "ptupitsyn (via GitHub)" <gi...@apache.org>.
ptupitsyn commented on code in PR #7277:
URL: https://github.com/apache/ignite-3/pull/7277#discussion_r2640024252
##########
modules/platforms/dotnet/README.md:
##########
@@ -60,6 +60,31 @@ IJobExecution<int> jobExecution = await client.Compute.SubmitAsync(
int wordCount = await jobExecution.GetResultAsync();
```
+## DI Integration
+
+Use `IgniteServicesCollectionExtensions.AddIgniteClientGroup` to register Ignite client in the dependency injection container:
Review Comment:
Yes I fixed it :+1:
> He
Don't anthropomorphize this thing :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-27423 .NET: Set LoggerFactory automatically in IgniteServiceCollectionExtensions [ignite-3]
Posted by "ptupitsyn (via GitHub)" <gi...@apache.org>.
ptupitsyn commented on code in PR #7277:
URL: https://github.com/apache/ignite-3/pull/7277#discussion_r2640024252
##########
modules/platforms/dotnet/README.md:
##########
@@ -60,6 +60,31 @@ IJobExecution<int> jobExecution = await client.Compute.SubmitAsync(
int wordCount = await jobExecution.GetResultAsync();
```
+## DI Integration
+
+Use `IgniteServicesCollectionExtensions.AddIgniteClientGroup` to register Ignite client in the dependency injection container:
Review Comment:
Yes I fixed it :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org