Skip to content

Commit

Permalink
A benchmark showing issue #1252
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerKratz committed Feb 17, 2021
1 parent 3ca27f8 commit 7b30707
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
3 changes: 2 additions & 1 deletion bench/Autofac.Benchmarks/Benchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public static class Benchmarks
typeof(PropertyInjectionBenchmark),
typeof(RootContainerResolveBenchmark),
typeof(OpenGenericBenchmark),
typeof(MultiConstructorBenchmark)
typeof(MultiConstructorBenchmark),
typeof(OnActivatedBenchmark)
};
}
}
36 changes: 36 additions & 0 deletions bench/Autofac.Benchmarks/OnActivatedBenchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using BenchmarkDotNet.Attributes;

namespace Autofac.Benchmarks
{
public class OnActivatedBenchmark
{
[Benchmark]
public void ResolveWithOnActivatedWithAction()
{
var builder = new ContainerBuilder();
Action<ContainerBuilder> someAction;
builder
.RegisterType<FakeService>()
.OnActivated(c =>
{
someAction = b =>
{
b.RegisterInstance(c.Instance);
};
});
using var container = builder.Build();
container.Resolve<FakeService>();
}

internal class FakeService
{
private IEnumerable<int> _data;
public FakeService()
{
_data = new int[1000];
}
}
}
}

0 comments on commit 7b30707

Please # to comment.