Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
364 changes: 228 additions & 136 deletions .editorconfig

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: "76b3d32d3f4b965e1d6425253c59407420ae2c43" # frozen: v0.47.0
rev: "e72a3ca1632f0b11a07d171449fe447a7ff6795e" # frozen: v0.48.0
hooks:
- id: markdownlint
args:
- --fix
- repo: https://github.com/tillig/json-sort-cli
rev: "009ab2ab49e1f2fa9d6b9dfc31009ceeca055204" # frozen: v3.0.0
rev: "2b7e147e0933bd30b58133b6f287e5c695ff4f0e" # frozen: v3.0.1
hooks:
- id: json-sort
args:
Expand Down
12 changes: 6 additions & 6 deletions bench/Autofac.BenchmarkProfiling/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace Autofac.BenchmarkProfiling;
/// <summary>
/// Simple command-line tool to invoke a benchmark manually in a way that helps with profiling each of the benchmarks.
/// </summary>
class Program
internal class Program
{
static void Main(string[] args)
private static void Main(string[] args)
{
// Pick a benchmark.
var availableBenchmarks = Benchmarks.BenchmarkSet.All;
Expand Down Expand Up @@ -84,7 +84,7 @@ static void Main(string[] args)

// Workload method is generated differently when BenchmarkDotNet actually runs; we'll need to wrap it in the set of parameters.
// It's way slower than they way they do it, but it should still give us good profiler results.
void workloadAction(int repeat)
void WorkloadAction(int repeat)
{
while (repeat > 0)
{
Expand All @@ -96,13 +96,13 @@ void workloadAction(int repeat)
setupAction.InvokeSingle();

// Warmup.
workloadAction(100);
WorkloadAction(100);

// Now start a new thread.
var runThread = new Thread(new ThreadStart(() =>
{
// Do a lot.
workloadAction(10000);
WorkloadAction(10000);
}))
{
Name = "Workload Thread"
Expand All @@ -124,7 +124,7 @@ private static void PrintBenchmarks(Type[] availableBenchmarks)

private static void PrintCases(BenchmarkRunInfo benchRunInfo)
{
for (int idx = 0; idx < benchRunInfo.BenchmarksCases.Length; idx++)
for (var idx = 0; idx < benchRunInfo.BenchmarksCases.Length; idx++)
{
var benchCase = benchRunInfo.BenchmarksCases[idx];
if (benchCase.HasParameters)
Expand Down
16 changes: 9 additions & 7 deletions bench/Autofac.Benchmarks/ConcurrencyBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@ public ConcurrencyBenchmark()
}

[Params(100 /*, 100, 1_000 */)]
public int ResolveTaskCount { get; set; }
public int ResolveTaskCount
{
get; set;
}

[Params(100 /*, 1_000, 10_000 */)]
public int ResolvesPerTask { get; set; }
public int ResolvesPerTask
{
get; set;
}

[Benchmark]
public async Task MultipleResolvesOnMultipleTasks()
Expand All @@ -40,11 +46,7 @@ public async Task MultipleResolvesOnMultipleTasks()
{
for (var j = 0; j < ResolvesPerTask; j++)
{
var instance = _container.Resolve<A>();
if (instance is null)
{
throw new InvalidOperationException("Instance is null");
}
var instance = _container.Resolve<A>() ?? throw new InvalidOperationException("Instance is null");
}
});
tasks.Add(task);
Expand Down
28 changes: 11 additions & 17 deletions bench/Autofac.Benchmarks/ConcurrencyNestedScopeBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@ public ConcurrencyNestedScopeBenchmark()
}

[Params(100 /*, 100, 1_000 */)]
public int ConcurrentRequests { get; set; }
public int ConcurrentRequests
{
get; set;
}

[Params(10)]
public int RepeatCount { get; set; }
public int RepeatCount
{
get; set;
}

[Benchmark]
public async Task MultipleResolvesOnMultipleTasks()
Expand All @@ -41,25 +47,13 @@ public async Task MultipleResolvesOnMultipleTasks()
// Start request
using (var requestScope = _container.BeginLifetimeScope("request"))
{
var service1 = requestScope.Resolve<MockRequestScopeService1>();
if (service1 == null)
{
throw new InvalidOperationException("Service1 is null");
}
var service1 = requestScope.Resolve<MockRequestScopeService1>() ?? throw new InvalidOperationException("Service1 is null");

using (var unitOfWorkScope = requestScope.BeginLifetimeScope())
{
var nestedRequestService2 = unitOfWorkScope.Resolve<MockRequestScopeService2>();
if (nestedRequestService2 == null)
{
throw new InvalidOperationException("Nested request service is null");
}
var nestedRequestService2 = unitOfWorkScope.Resolve<MockRequestScopeService2>() ?? throw new InvalidOperationException("Nested request service is null");

var unitOfWork = unitOfWorkScope.Resolve<MockUnitOfWork>();
if (unitOfWork == null)
{
throw new InvalidOperationException("Unit of work is null");
}
var unitOfWork = unitOfWorkScope.Resolve<MockUnitOfWork>() ?? throw new InvalidOperationException("Unit of work is null");
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions bench/Autofac.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ private static bool TryMatchBaselineArg(string arg, out string? valueFromAssignm
{
valueFromAssignment = null;

static bool Matches(string candidate) =>
candidate.Equals("--baseline-version", StringComparison.OrdinalIgnoreCase) ||
static bool Matches(string candidate)
=> candidate.Equals("--baseline-version", StringComparison.OrdinalIgnoreCase) ||
candidate.Equals("--baselineVersion", StringComparison.OrdinalIgnoreCase);

var equalsIndex = arg.AsSpan().IndexOf('=');
Expand Down
30 changes: 24 additions & 6 deletions bench/Autofac.Benchmarks/PropertyInjectionBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,47 @@ public void Resolve()

internal class A
{
public B1? B1 { get; set; }
public B1? B1
{
get; set;
}

public B2? B2 { get; set; }
public B2? B2
{
get; set;
}
}

internal class B1
{
public C1? C1 { get; set; }
public C1? C1
{
get; set;
}
}

internal class B2
{
public C2? C2 { get; set; }
public C2? C2
{
get; set;
}
}

internal class C1
{
public D1? D1 { get; set; }
public D1? D1
{
get; set;
}
}

internal class C2
{
public D2? D2 { get; set; }
public D2? D2
{
get; set;
}
}

internal class D1
Expand Down
20 changes: 16 additions & 4 deletions bench/Autofac.Benchmarks/RequiredPropertyBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,27 @@ public ConstructorComponent(ServiceA serviceA, ServiceB serviceB)
ServiceB = serviceB;
}

public ServiceA ServiceA { get; }
public ServiceA ServiceA
{
get;
}

public ServiceB ServiceB { get; }
public ServiceB ServiceB
{
get;
}
}

private class RequiredPropertyComponent
{
public required ServiceA ServiceA { get; set; }
public required ServiceA ServiceA
{
get; set;
}

public required ServiceA ServiceB { get; set; }
public required ServiceA ServiceB
{
get; set;
}
}
}
3 changes: 3 additions & 0 deletions build/stylecop.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"licenseName": "MIT"
},
"xmlHeader": false
},
"orderingRules": {
"usingDirectivesPlacement": "outsideNamespace"
}
}
}
10 changes: 5 additions & 5 deletions codegen/Autofac.CodeGen/DelegateRegisterGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
{
// Set up an incremental generator that regenerates when the 'RegistrationExtensions' class changes.
// Capture the INamedTypeSymbol when it does.
IncrementalValuesProvider<INamedTypeSymbol> classDeclarations = context.SyntaxProvider
var classDeclarations = context.SyntaxProvider
.CreateSyntaxProvider(
predicate: static (s, _) => s is ClassDeclarationSyntax classSyn && classSyn.Modifiers.Any(static m => m.IsKind(SyntaxKind.PartialKeyword)),
transform: static (context, cancelToken) =>
Expand All @@ -47,7 +47,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
.Where(static m => m is not null)!;

// Just get our first one (will only be one instance anyway, we just need to convert to a single value provider).
IncrementalValueProvider<INamedTypeSymbol?> firstSyntax
var firstSyntax
= classDeclarations.Collect().Select((all, _) => all.FirstOrDefault());

context.RegisterSourceOutput(
Expand All @@ -74,9 +74,9 @@ private static void Execute(SourceProductionContext spc, INamedTypeSymbol? regEx
spc,
"RegistrationExtensions",
"Register",
static (int argCount, bool hasComponentContext) => hasComponentContext ?
$"DelegateInvokers.DelegateInvoker{argCount}WithComponentContext" :
$"DelegateInvokers.DelegateInvoker{argCount}",
static (int argCount, bool hasComponentContext) => hasComponentContext
? $"DelegateInvokers.DelegateInvoker{argCount}WithComponentContext"
: $"DelegateInvokers.DelegateInvoker{argCount}",
NumberOfGenericArgs);
}

Expand Down
4 changes: 2 additions & 2 deletions default.proj
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
<Exec Command="dotnet build &quot;%(SolutionFile.FullPath)&quot; -c $(Configuration) /p:Version=$(Version)" />
</Target>
<Target Name="Package">
<MakeDir Directories="$([System.IO.Path]::Combine($(PackageDirectory),%(PublishProject.Filename)))" />
<Exec Command="dotnet pack &quot;%(SolutionFile.FullPath)&quot; -c $(Configuration) --output &quot;$(PackageDirectory)&quot; /p:Version=$(Version)" />
<MakeDir Directories="$(PackageDirectory)" />
<Exec Command="dotnet pack &quot;%(SourceProject.Identity)&quot; -c $(Configuration) --no-build --output &quot;$(PackageDirectory)&quot; /p:Version=$(Version)" />
</Target>
<Target Name="Test">
<MakeDir Directories="$(LogDirectory)" />
Expand Down
6 changes: 3 additions & 3 deletions src/Autofac/Builder/BuildCallbackManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ internal static class BuildCallbackManager
{
private const string BuildCallbacksExecutedKey = nameof(BuildCallbacksExecutedKey);

private static readonly TypedService CallbackServiceType = new(typeof(BuildCallbackService));
private static readonly TypedService _callbackServiceType = new(typeof(BuildCallbackService));

/// <summary>
/// Executes the newly-registered build callbacks for a given scope/container..
/// </summary>
/// <param name="scope">The new scope/container.</param>
internal static void RunBuildCallbacks(ILifetimeScope scope)
{
var buildCallbackServices = scope.ComponentRegistry.ServiceRegistrationsFor(CallbackServiceType);
var buildCallbackServices = scope.ComponentRegistry.ServiceRegistrationsFor(_callbackServiceType);

foreach (var srv in buildCallbackServices)
{
Expand All @@ -30,7 +30,7 @@ internal static void RunBuildCallbacks(ILifetimeScope scope)
continue;
}

var request = new ResolveRequest(CallbackServiceType, srv, Enumerable.Empty<Parameter>());
var request = new ResolveRequest(_callbackServiceType, srv, Enumerable.Empty<Parameter>());
var component = (BuildCallbackService)scope.ResolveComponent(request);
srv.Registration.Metadata[BuildCallbacksExecutedKey] = true;

Expand Down
5 changes: 4 additions & 1 deletion src/Autofac/Builder/DeferredCallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,8 @@ public Action<IComponentRegistryBuilder> Callback
/// A <see cref="Guid"/> that uniquely identifies the callback action
/// in a set of callbacks.
/// </value>
public Guid Id { get; }
public Guid Id
{
get;
}
}
5 changes: 4 additions & 1 deletion src/Autofac/Builder/IConcreteActivatorData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ public interface IConcreteActivatorData
/// <summary>
/// Gets the instance activator based on the provided data.
/// </summary>
IInstanceActivator Activator { get; }
IInstanceActivator Activator
{
get;
}
}
20 changes: 16 additions & 4 deletions src/Autofac/Builder/IRegistrationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,37 @@ public interface IRegistrationBuilder<out TLimit, out TActivatorData, out TRegis
/// Gets the registration data.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
RegistrationData RegistrationData { get; }
RegistrationData RegistrationData
{
get;
}

/// <summary>
/// Gets the activator data.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
TActivatorData ActivatorData { get; }
TActivatorData ActivatorData
{
get;
}

/// <summary>
/// Gets the registration style.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
TRegistrationStyle RegistrationStyle { get; }
TRegistrationStyle RegistrationStyle
{
get;
}

/// <summary>
/// Gets the resolve pipeline for this registration.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
IResolvePipelineBuilder ResolvePipeline { get; }
IResolvePipelineBuilder ResolvePipeline
{
get;
}

/// <summary>
/// Configure the component so that instances are never disposed by the container.
Expand Down
Loading
Loading