Skip to content

Commit

Permalink
Fix incorrect behavior when using false value.
Browse files Browse the repository at this point in the history
Improved weighting when choosing correct overload.
Added more tests and improved test naming.
Renamed extension classes to identify the library.
Run Code Cleanup.
  • Loading branch information
Donn Relacion committed Jul 3, 2022
1 parent 8ad4650 commit 37e9e65
Show file tree
Hide file tree
Showing 47 changed files with 2,934 additions and 2,943 deletions.
46 changes: 23 additions & 23 deletions sample/TestWebApi/Controllers/WeatherForecastController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@

namespace TestWebApi.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

private readonly ILogger<WeatherForecastController> _logger;
private readonly ILogger<WeatherForecastController> _logger;

public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}

[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
}
[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
}
}
4 changes: 2 additions & 2 deletions sample/TestWebApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();
Expand Down
5 changes: 5 additions & 0 deletions sample/TestWebApi/TestWebApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="OpenTelemetry.Exporter.Jaeger" Version="1.3.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.0.0-rc9.4" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.0.0-rc9.4" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.0.0-rc9.4" />
<PackageReference Include="OpenTelemetry.Instrumentation.SqlClient" Version="1.0.0-rc9.4" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions sample/TestWebApi/WeatherForecast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ namespace TestWebApi;

public class WeatherForecast
{
public DateTime Date { get; set; }
public DateTime Date { get; set; }

public int TemperatureC { get; set; }
public int TemperatureC { get; set; }

public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);

public string? Summary { get; set; }
public string? Summary { get; set; }
}
51 changes: 27 additions & 24 deletions sample/TestWebApi/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"Services": {
"Logging": true,
"Hsts": {
"ExcludedHosts": {
"Clear": true
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"Services": {
"Logging": true,
"Hsts": {
"Preload": true,
"IncludeSubDomains": true,
"MaxAge": "356.00:00:00"
},
"Preload": true,
"IncludeSubDomains": true,
"MaxAge": "356.00:00:00"
},
"Configure<Microsoft.AspNetCore.Builder.CookiePolicyOptions>": {
"HttpOnly": "Always",
"Secure": "Always"
},
"Controllers": true,
"EndpointsApiExplorer": true,
"SwaggerGen": true
}
"Configure<Microsoft.AspNetCore.Builder.CookiePolicyOptions>": {
"HttpOnly": "Always",
"Secure": "Always"
},
"Controllers": true,
"EndpointsApiExplorer": true,
"SwaggerGen": true,
"OpenTelemetryTracing": {
"AspNetCoreInstrumentation": true,
"HttpClientInstrumentation": true,
"SqlClientInstrumentation": true,
"JaegerExporter": true
}
}
}
2 changes: 0 additions & 2 deletions src/ConfigurationProcessor.AspNetCore/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@
// Copyright (c) almostchristian. All rights reserved.
// -------------------------------------------------------------------------------------------------

using System;

[assembly: CLSCompliant(false)]
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// -------------------------------------------------------------------------------------------------
// Copyright (c) almostchristian. All rights reserved.
// -------------------------------------------------------------------------------------------------

using Microsoft.AspNetCore.Builder;

namespace Microsoft.Extensions.DependencyInjection
{
/// <summary>
/// Contains extension methods.
/// </summary>
public static class ConfigurationProcessorWebApplicationBuilderExtensions
{
/// <summary>
/// Adds services from configuration.
/// </summary>
/// <param name="builder">The application builder.</param>
/// <param name="servicesSection">The config section that contains the services.</param>
/// <returns>The <paramref name="builder"/> for chaining.</returns>
public static WebApplicationBuilder AddServicesFromConfiguration(this WebApplicationBuilder builder, string servicesSection)
{
ArgumentNullException.ThrowIfNull(builder);
builder.Services.AddFromConfiguration(builder.Configuration, servicesSection);
return builder;
}
}
}

This file was deleted.

72 changes: 36 additions & 36 deletions src/ConfigurationProcessor.Core/Assemblies/AssemblyFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,47 @@

namespace ConfigurationProcessor.Core.Assemblies
{
internal abstract class AssemblyFinder
{
public abstract IReadOnlyList<AssemblyName> FindAssembliesReferencingAssembly(Assembly[] markerAssemblies);
internal abstract class AssemblyFinder
{
public abstract IReadOnlyList<AssemblyName> FindAssembliesReferencingAssembly(Assembly[] markerAssemblies);

protected static bool IsCaseInsensitiveMatch(string? text, string textToFind)
{
return text != null && text.IndexOf(textToFind, StringComparison.OrdinalIgnoreCase) >= 0;
}
protected static bool IsCaseInsensitiveMatch(string? text, string textToFind)
{
return text != null && text.IndexOf(textToFind, StringComparison.OrdinalIgnoreCase) >= 0;
}

public static AssemblyFinder Auto()
{
try
public static AssemblyFinder Auto()
{
try
{
// Need to check `Assembly.GetEntryAssembly()` first because
// `DependencyContext.Default` throws an exception when `Assembly.GetEntryAssembly()` returns null
if (Assembly.GetEntryAssembly() != null && DependencyContext.Default != null)
{
// Need to check `Assembly.GetEntryAssembly()` first because
// `DependencyContext.Default` throws an exception when `Assembly.GetEntryAssembly()` returns null
if (Assembly.GetEntryAssembly() != null && DependencyContext.Default != null)
{
return new DependencyContextAssemblyFinder(DependencyContext.Default);
}
}
catch (NotSupportedException) when (string.IsNullOrEmpty(typeof(object).Assembly.Location))
{
// bundled mode detection
return new DependencyContextAssemblyFinder(DependencyContext.Default);
}
}
catch (NotSupportedException) when (string.IsNullOrEmpty(typeof(object).Assembly.Location))
{
// bundled mode detection
}

return new DllScanningAssemblyFinder();
}
return new DllScanningAssemblyFinder();
}

public static AssemblyFinder ForSource(ConfigurationAssemblySource configurationAssemblySource)
{
return configurationAssemblySource switch
{
ConfigurationAssemblySource.UseLoadedAssemblies => Auto(),
ConfigurationAssemblySource.AlwaysScanDllFiles => new DllScanningAssemblyFinder(),
_ => throw new ArgumentOutOfRangeException(nameof(configurationAssemblySource), configurationAssemblySource, null),
};
}
public static AssemblyFinder ForSource(ConfigurationAssemblySource configurationAssemblySource)
{
return configurationAssemblySource switch
{
ConfigurationAssemblySource.UseLoadedAssemblies => Auto(),
ConfigurationAssemblySource.AlwaysScanDllFiles => new DllScanningAssemblyFinder(),
_ => throw new ArgumentOutOfRangeException(nameof(configurationAssemblySource), configurationAssemblySource, null),
};
}

public static AssemblyFinder ForDependencyContext(DependencyContext dependencyContext)
{
return new DependencyContextAssemblyFinder(dependencyContext);
}
}
public static AssemblyFinder ForDependencyContext(DependencyContext dependencyContext)
{
return new DependencyContextAssemblyFinder(dependencyContext);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@
// limitations under the License.
namespace ConfigurationProcessor.Core.Assemblies
{
/// <summary>
/// Defines how the package will identify the assemblies which are scanned for sinks and other Type information.
/// </summary>
public enum ConfigurationAssemblySource
{
/// <summary>
/// Try to scan the assemblies already in memory. This is the default. If GetEntryAssembly is null, fallback to DLL scanning.
/// </summary>
UseLoadedAssemblies,
/// <summary>
/// Defines how the package will identify the assemblies which are scanned for sinks and other Type information.
/// </summary>
public enum ConfigurationAssemblySource
{
/// <summary>
/// Try to scan the assemblies already in memory. This is the default. If GetEntryAssembly is null, fallback to DLL scanning.
/// </summary>
UseLoadedAssemblies,

/// <summary>
/// Scan for assemblies in DLLs from the working directory. This is the fallback when GetEntryAssembly is null.
/// </summary>
AlwaysScanDllFiles,
}
/// <summary>
/// Scan for assemblies in DLLs from the working directory. This is the fallback when GetEntryAssembly is null.
/// </summary>
AlwaysScanDllFiles,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@

namespace ConfigurationProcessor.Core.Assemblies
{
internal sealed class DependencyContextAssemblyFinder : AssemblyFinder
{
private readonly DependencyContext dependencyContext;
internal sealed class DependencyContextAssemblyFinder : AssemblyFinder
{
private readonly DependencyContext dependencyContext;

public DependencyContextAssemblyFinder(DependencyContext dependencyContext)
{
this.dependencyContext = dependencyContext ?? throw new ArgumentNullException(nameof(dependencyContext));
}
public DependencyContextAssemblyFinder(DependencyContext dependencyContext)
{
this.dependencyContext = dependencyContext ?? throw new ArgumentNullException(nameof(dependencyContext));
}

public override IReadOnlyList<AssemblyName> FindAssembliesReferencingAssembly(Assembly[] markerAssemblies)
{
var query = from assemblyName in this.dependencyContext.RuntimeLibraries
.SelectMany(l => l.GetDefaultAssemblyNames(this.dependencyContext)).Distinct()
select assemblyName;
public override IReadOnlyList<AssemblyName> FindAssembliesReferencingAssembly(Assembly[] markerAssemblies)
{
var query = from assemblyName in this.dependencyContext.RuntimeLibraries
.SelectMany(l => l.GetDefaultAssemblyNames(this.dependencyContext)).Distinct()
select assemblyName;

return query.ToList().AsReadOnly();
}
}
return query.ToList().AsReadOnly();
}
}
}
Loading

0 comments on commit 37e9e65

Please sign in to comment.