-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve perf of ActivatorUtilities.CreateInstance() (#91290)
- Loading branch information
1 parent
38445c3
commit 00937b2
Showing
5 changed files
with
372 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
.../Microsoft.Extensions.DependencyInjection/tests/CollectibleAssembly/CollectableClasses.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace CollectibleAssembly | ||
{ | ||
public class ClassToCreate | ||
{ | ||
public object ClassAsCtorArgument { get; set; } | ||
|
||
public ClassToCreate(ClassAsCtorArgument obj) { ClassAsCtorArgument = obj; } | ||
|
||
public static object Create(ServiceProvider provider) | ||
{ | ||
// Both the type to create (ClassToCreate) and the ctor's arg type (ClassAsCtorArgument) are | ||
// located in this assembly, so both types need to be GC'd for this assembly to be collected. | ||
return ActivatorUtilities.CreateInstance<ClassToCreate>(provider, new ClassAsCtorArgument()); | ||
} | ||
} | ||
|
||
public class ClassAsCtorArgument | ||
{ | ||
} | ||
} |
Oops, something went wrong.