Skip to content

Commit

Permalink
Fix duplicate providers issue (#318)
Browse files Browse the repository at this point in the history
* #317: Bump to version 1.0.6

* #317: Bump to Configuration 1.0.7

* Update Grid.Bot.Recovery.csproj

Signed-off-by: Nikita Petko <petko@vmminfra.net>

* Update Shared.Settings.csproj

Signed-off-by: Nikita Petko <petko@vmminfra.net>

* #317: Do not use SELECT for singletons.

While the array produced only has about 13 elements, using LinQ select on it causes it to produce over 60 singletons.

---------

Signed-off-by: Nikita Petko <petko@vmminfra.net>
  • Loading branch information
jf-06 authored Jun 18, 2024
1 parent f2e9068 commit 6c97314
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 25 deletions.
4 changes: 2 additions & 2 deletions services/recovery/Grid.Bot.Recovery.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

<PropertyGroup>
<Description>Recovery executable for the MFDLABS grid-bot.</Description>
</PropertyGroup>
</PropertyGroup>

<ItemGroup Label="PrivatePackages" Condition=" '$(LocalBuild)' != 'true' ">
<PackageReference Include="Configuration" Version="1.0.5" />
<PackageReference Include="Configuration" Version="1.0.7" />
<PackageReference Include="Logging" Version="1.0.4" />
<PackageReference Include="Networking" Version="1.0.5" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions shared/settings/Shared.Settings.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</ItemGroup>

<ItemGroup Label="PrivatePackages" Condition=" '$(LocalBuild)' != 'true' ">
<PackageReference Include="Configuration" Version="1.0.5" />
<PackageReference Include="Configuration" Version="1.0.7" />
<PackageReference Include="Redis" Version="1.0.4" />
<PackageReference Include="ServiceDiscovery" Version="1.0.4" />
<PackageReference Include="FloodCheckers.Redis" Version="1.0.4" />
Expand Down Expand Up @@ -45,4 +45,4 @@
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.0" />
</ItemGroup>

</Project>
</Project>
57 changes: 36 additions & 21 deletions src/Runner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,31 +203,39 @@ private static IEnumerable<IConfigurationProvider> GetSettingsProviders()
var assembly = Assembly.GetAssembly(typeof(BaseSettingsProvider));
var ns = typeof(BaseSettingsProvider).Namespace;

var singletons = assembly
var types = assembly
.GetTypes()
.Where(t => string.Equals(t.Namespace, ns, StringComparison.Ordinal) &&
t.BaseType.Name == typeof(BaseSettingsProvider).Name) // finicky
.Select(t =>
t.BaseType.Name == typeof(BaseSettingsProvider).Name)
.ToList(); // finicky

var singletons = new List<IConfigurationProvider>();

foreach (var t in types)
{
// Construct the singleton.
var constructor = t.GetConstructor(Type.EmptyTypes);
if (constructor == null)
{
// Construct the singleton.
var constructor = t.GetConstructor(Type.EmptyTypes);
if (constructor == null)
{
Console.Error.WriteLine("Provider {0} did not expose a public constructor!", t.FullName);
Console.Error.WriteLine("Provider {0} did not expose a public constructor!", t.FullName);

return null;
}
singletons.Add(null);

var singleton = constructor.Invoke(null);
if (singleton == null)
{
Console.Error.WriteLine("Provider {0} did not construct a singleton!", t.FullName);
continue;
}

var singleton = constructor.Invoke(null);
if (singleton == null || singleton is not IConfigurationProvider provider)
{
Console.Error.WriteLine("Provider {0} did not construct a singleton!", t.FullName);

return null;
}
singletons.Add(null);

return singleton;
});
continue;
}

singletons.Add(provider);
}

return singletons.Cast<IConfigurationProvider>();
}
Expand Down Expand Up @@ -383,10 +391,17 @@ private static void StartGrpcServer(IEnumerable<string> args, IServiceProvider s
options.ConfigureEndpointDefaults(listenOptions =>
{
listenOptions.Protocols = HttpProtocols.Http2;
listenOptions.UseHttps(globalSettings.GrpcServerCertificatePath, globalSettings.GrpcServerCertificatePassword, httpsOptions =>

try
{
listenOptions.UseHttps(globalSettings.GrpcServerCertificatePath, globalSettings.GrpcServerCertificatePassword, httpsOptions =>
{
httpsOptions.SslProtocols = SslProtocols.Tls13 | SslProtocols.Tls12;
});
} catch (Exception ex)
{
httpsOptions.SslProtocols = SslProtocols.Tls13 | SslProtocols.Tls12;
});
logger.Warning("Failed to configure gRPC with HTTPS because: {0}. Will resort to insecure host instead!", ex.Message);
}
});
});

Expand Down

0 comments on commit 6c97314

Please sign in to comment.