-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from CrackAndDie/dev
New container implementation and more
- Loading branch information
Showing
82 changed files
with
1,869 additions
and
472 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
2 changes: 1 addition & 1 deletion
2
Hypocrite.Avalonia/Localization/LocalizationChangedObservable.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
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
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
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
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,14 @@ | ||
namespace Hypocrite.Benchmarks.Container | ||
{ | ||
public class ContainerTestClass | ||
{ | ||
public int Id { get; set; } | ||
public string Name { get; set; } | ||
|
||
public ContainerTestClass(int id, string name) | ||
{ | ||
Id = id; | ||
Name = name; | ||
} | ||
} | ||
} |
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,8 @@ | ||
namespace Hypocrite.Benchmarks.Container | ||
{ | ||
public class ContainerTestClass2 | ||
{ | ||
public int Id { get; set; } | ||
public string Name { get; set; } | ||
} | ||
} |
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,21 @@ | ||
using Hypocrite.Core.Container; | ||
using Unity; | ||
|
||
namespace Hypocrite.Benchmarks.Container | ||
{ | ||
public class ContainerTestClass3Light | ||
{ | ||
public int Id { get; set; } | ||
public string Name { get; set; } | ||
[Injection] | ||
public ContainerTestClass2 TestClass { get; set; } | ||
} | ||
|
||
public class ContainerTestClass3Unity | ||
{ | ||
public int Id { get; set; } | ||
public string Name { get; set; } | ||
[Dependency] | ||
public ContainerTestClass2 TestClass { get; set; } | ||
} | ||
} |
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,29 @@ | ||
using Hypocrite.Core.Container; | ||
using Unity; | ||
|
||
namespace Hypocrite.Benchmarks.Container | ||
{ | ||
public class ContainerTestClass4Light | ||
{ | ||
public int Id { get; set; } | ||
public string Name { get; set; } | ||
public ContainerTestClass2 TestClass { get; set; } | ||
|
||
public ContainerTestClass4Light([Injection] ContainerTestClass2 testClass) | ||
{ | ||
TestClass = testClass; | ||
} | ||
} | ||
|
||
public class ContainerTestClass4Unity | ||
{ | ||
public int Id { get; set; } | ||
public string Name { get; set; } | ||
public ContainerTestClass2 TestClass { get; set; } | ||
|
||
public ContainerTestClass4Unity([Dependency] ContainerTestClass2 testClass) | ||
{ | ||
TestClass = testClass; | ||
} | ||
} | ||
} |
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,34 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using Hypocrite.Core.Container; | ||
using Hypocrite.Core.Container.Interfaces; | ||
using Unity; | ||
|
||
namespace Hypocrite.Benchmarks.Container | ||
{ | ||
[MemoryDiagnoser] | ||
public class IsRegistered | ||
{ | ||
ILightContainer _lightContainer; | ||
IUnityContainer _unityContainer; | ||
|
||
public IsRegistered() | ||
{ | ||
_lightContainer = new LightContainer(); | ||
_lightContainer.RegisterType(typeof(ContainerTestClass2), typeof(ContainerTestClass2)); | ||
_unityContainer = new UnityContainer(); | ||
_unityContainer.RegisterType<ContainerTestClass2>(); | ||
} | ||
|
||
[Benchmark] | ||
public bool WithUnityContainer() | ||
{ | ||
return _unityContainer.IsRegistered<ContainerTestClass2>(); | ||
} | ||
|
||
[Benchmark] | ||
public bool WithLightContainer() | ||
{ | ||
return _lightContainer.IsRegistered(typeof(ContainerTestClass2)); | ||
} | ||
} | ||
} |
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,48 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using Hypocrite.Core.Container; | ||
using Hypocrite.Core.Container.Extensions; | ||
|
||
namespace Hypocrite.Benchmarks.Container | ||
{ | ||
[MemoryDiagnoser] | ||
public class LightContainerSteps | ||
{ | ||
LightContainer _lightContainer; | ||
|
||
public LightContainerSteps() | ||
{ | ||
_lightContainer = new LightContainer(); | ||
_lightContainer.RegisterType(typeof(ContainerTestClass2), typeof(ContainerTestClass2), false); | ||
} | ||
|
||
[Benchmark] | ||
public void IsRegistered() | ||
{ | ||
_lightContainer.IsRegistered(typeof(ContainerTestClass2)); | ||
} | ||
|
||
[Benchmark] | ||
public void GetRegistration() | ||
{ | ||
_lightContainer.GetRegistration(typeof(ContainerTestClass2), string.Empty); | ||
} | ||
|
||
// it takes about 60ns | ||
// var _ = reg.RegistrationPolicy.CreateInstance(true); | ||
|
||
[Benchmark] | ||
public void CreatePureInstance() | ||
{ | ||
var reg = _lightContainer.GetRegistration(typeof(ContainerTestClass2), string.Empty); | ||
var _ = _lightContainer.InstanceCreator.CreatePureInstance(reg); | ||
} | ||
|
||
[Benchmark] | ||
public void CreateInstance() | ||
{ | ||
var reg = _lightContainer.GetRegistration(typeof(ContainerTestClass2), string.Empty); | ||
var inst = _lightContainer.InstanceCreator.CreatePureInstance(reg); | ||
_lightContainer.InstanceCreator.ResolveInjections(inst, reg.MemberInjectionInfo); | ||
} | ||
} | ||
} |
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,40 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using Hypocrite.Core.Container; | ||
using Hypocrite.Core.Container.Interfaces; | ||
using Hypocrite.Core.Container.Extensions; | ||
using Unity; | ||
using System.Collections.Generic; | ||
|
||
namespace Hypocrite.Benchmarks.Container | ||
{ | ||
[MemoryDiagnoser] | ||
public class ResolveOverloadType | ||
{ | ||
ILightContainer _lightContainer; | ||
IUnityContainer _unityContainer; | ||
|
||
public ResolveOverloadType() | ||
{ | ||
_lightContainer = new LightContainer(); | ||
_unityContainer = new UnityContainer(); | ||
|
||
for (char c = 'A'; c <= 'Z'; ++c) | ||
{ | ||
_lightContainer.RegisterType<ContainerTestClass2>(c.ToString()); | ||
_unityContainer.RegisterType<ContainerTestClass2>(c.ToString()); | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public ContainerTestClass2 WithUnityContainer() | ||
{ | ||
return _unityContainer.Resolve<ContainerTestClass2>("K"); | ||
} | ||
|
||
[Benchmark] | ||
public ContainerTestClass2 WithLightContainer() | ||
{ | ||
return _lightContainer.Resolve<ContainerTestClass2>("K"); | ||
} | ||
} | ||
} |
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,35 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using Hypocrite.Core.Container; | ||
using Hypocrite.Core.Container.Interfaces; | ||
using System.Linq.Expressions; | ||
using Unity; | ||
|
||
namespace Hypocrite.Benchmarks.Container | ||
{ | ||
[MemoryDiagnoser] | ||
public class ResolveSingleton | ||
{ | ||
ILightContainer _lightContainer; | ||
IUnityContainer _unityContainer; | ||
|
||
public ResolveSingleton() | ||
{ | ||
_lightContainer = new LightContainer(); | ||
_lightContainer.RegisterType(typeof(ContainerTestClass2), typeof(ContainerTestClass2), true); | ||
_unityContainer = new UnityContainer(); | ||
_unityContainer.RegisterSingleton<ContainerTestClass2>(); | ||
} | ||
|
||
[Benchmark] | ||
public ContainerTestClass2 WithUnityContainer() | ||
{ | ||
return _unityContainer.Resolve<ContainerTestClass2>(); | ||
} | ||
|
||
[Benchmark] | ||
public ContainerTestClass2 WithLightContainer() | ||
{ | ||
return _lightContainer.Resolve(typeof(ContainerTestClass2)) as ContainerTestClass2; | ||
} | ||
} | ||
} |
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,34 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using Hypocrite.Core.Container; | ||
using Hypocrite.Core.Container.Interfaces; | ||
using Unity; | ||
|
||
namespace Hypocrite.Benchmarks.Container | ||
{ | ||
[MemoryDiagnoser] | ||
public class ResolveType | ||
{ | ||
ILightContainer _lightContainer; | ||
IUnityContainer _unityContainer; | ||
|
||
public ResolveType() | ||
{ | ||
_lightContainer = new LightContainer(); | ||
_lightContainer.RegisterType(typeof(ContainerTestClass2), typeof(ContainerTestClass2)); | ||
_unityContainer = new UnityContainer(); | ||
_unityContainer.RegisterType<ContainerTestClass2>(); | ||
} | ||
|
||
[Benchmark] | ||
public ContainerTestClass2 WithUnityContainer() | ||
{ | ||
return _unityContainer.Resolve<ContainerTestClass2>(); | ||
} | ||
|
||
[Benchmark] | ||
public ContainerTestClass2 WithLightContainer() | ||
{ | ||
return _lightContainer.Resolve(typeof(ContainerTestClass2)) as ContainerTestClass2; | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
Hypocrite.Benchmarks/Container/ResolveTypeWithCtorInjection.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,36 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using Hypocrite.Core.Container; | ||
using Hypocrite.Core.Container.Interfaces; | ||
using Unity; | ||
|
||
namespace Hypocrite.Benchmarks.Container | ||
{ | ||
[MemoryDiagnoser] | ||
public class ResolveTypeWithCtorInjection | ||
{ | ||
ILightContainer _lightContainer; | ||
IUnityContainer _unityContainer; | ||
|
||
public ResolveTypeWithCtorInjection() | ||
{ | ||
_lightContainer = new LightContainer(); | ||
_lightContainer.RegisterType(typeof(ContainerTestClass2), typeof(ContainerTestClass2)); | ||
_lightContainer.RegisterType(typeof(ContainerTestClass4Light), typeof(ContainerTestClass4Light)); | ||
_unityContainer = new UnityContainer(); | ||
_unityContainer.RegisterType<ContainerTestClass2>(); | ||
_unityContainer.RegisterType<ContainerTestClass4Unity>(); | ||
} | ||
|
||
[Benchmark] | ||
public int WithUnityContainer() | ||
{ | ||
return _unityContainer.Resolve<ContainerTestClass4Unity>().TestClass.Id; | ||
} | ||
|
||
[Benchmark] | ||
public int WithLightContainer() | ||
{ | ||
return (_lightContainer.Resolve(typeof(ContainerTestClass4Light)) as ContainerTestClass4Light).TestClass.Id; | ||
} | ||
} | ||
} |
Oops, something went wrong.