Skip to content

Commit 7372f0a

Browse files
committed
Refactoring to allow removing of HierarchicalLifetimeStrategy
1 parent 6b839e5 commit 7372f0a

File tree

5 files changed

+73
-2
lines changed

5 files changed

+73
-2
lines changed

package.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22

33
<PropertyGroup>
4-
<Version>2.1.2</Version>
4+
<Version>2.2.0</Version>
55
<PackageReleaseNotes>This package is distributed as .NET Standard 1.0, 2.0, .Net Core 1.0 and .NET 4.0, 4.5, 4.7</PackageReleaseNotes>
66
</PropertyGroup>
77

src/Lifetime/HierarchicalLifetimeManager.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
22

33
using System;
4+
using Unity.Policy;
45

56
namespace Unity.Lifetime
67
{
@@ -22,6 +23,11 @@ public override void RemoveValue()
2223
Dispose();
2324
}
2425

26+
public IBuilderPolicy CreateScope()
27+
{
28+
return new HierarchicalLifetimeManager();
29+
}
30+
2531

2632
#region IDisposable
2733

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
namespace Unity.Lifetime
1+
using Unity.Policy;
2+
3+
namespace Unity.Lifetime
24
{
35
public interface IHierarchicalLifetimePolicy : ILifetimePolicy
46
{
7+
/// <summary>
8+
/// Creates controller for current scope
9+
/// </summary>
10+
/// <returns>IScopeLifetimePolicy</returns>
11+
IBuilderPolicy CreateScope();
512
}
613
}

src/Registration/IIndexerOf.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+

2+
namespace Unity.Registration
3+
{
4+
public interface IIndexerOf<TKey, TValue>
5+
{
6+
TValue this[TKey index] { get; set; }
7+
}
8+
9+
}

src/Utility/Prime.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System;
2+
3+
namespace Unity.Utility
4+
{
5+
public static class Prime
6+
{
7+
public static readonly int[] Numbers = {
8+
1, 3, 7, 11, 17, 23, 29, 37, 47, 59, 71, 89, 107, 131, 163, 197, 239, 293,
9+
353, 431, 521, 631, 761, 919, 1103, 1327, 1597, 1931, 2333, 2801, 3371, 4049,
10+
4861, 5839, 7013, 8419, 10103, 12143, 14591, 17519, 21023, 25229, 30293, 36353,
11+
43627, 52361, 62851, 75431, 90523, 108631, 130363, 156437, 187751, 225307, 270371,
12+
324449, 389357, 467237, 560689, 672827, 807403, 968897, 1162687, 1395263, 1674319,
13+
2009191, 2411033, 2893249, 3471899, 4166287, 4999559, 5999471, 7199369, 10000019};
14+
15+
16+
public static int GetPrime(int min)
17+
{
18+
if (min < 0) throw new ArgumentException("Capacity Overflow");
19+
20+
foreach (var prime in Numbers)
21+
{
22+
if (prime >= min) return prime;
23+
}
24+
25+
for (var i = min | 1; i < Int32.MaxValue; i += 2)
26+
{
27+
if (IsPrime(i) && (i - 1) % 101 != 0)
28+
return i;
29+
}
30+
31+
return min;
32+
}
33+
34+
public static bool IsPrime(int candidate)
35+
{
36+
if ((candidate & 1) != 0)
37+
{
38+
var limit = (int)Math.Sqrt(candidate);
39+
for (var divisor = 3; divisor <= limit; divisor += 2)
40+
{
41+
if (candidate % divisor == 0)
42+
return false;
43+
}
44+
return true;
45+
}
46+
return candidate == 2;
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)