Skip to content

Commit 5b2b2c6

Browse files
committed
Corrected bug on instantiation with configuration, StructureMapDependencyResolution class renamed to StructureMapRepositoryDependencyResolution
1 parent 8a196b2 commit 5b2b2c6

8 files changed

Lines changed: 18 additions & 13 deletions

File tree

SharpRepository.Ioc.StructureMap/Factories/CompoundKey.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ public override Instance CloseType(Type[] types)
4444
{
4545
var instanceType = typeof(RepositoryCompoundKeyInstance<>).MakeGenericType(types);
4646

47-
if (this.configuration != null) {
48-
return Activator.CreateInstance(instanceType,this.configuration, this.repositoryName) as Instance;
47+
if (this.configuration != null) {
48+
var ctor = instanceType.GetConstructor(new[] { typeof(ISharpRepositoryConfiguration) });
49+
return ctor.Invoke(new object[] { this.configuration }) as Instance;
4950
} else {
5051
var ctor = instanceType.GetConstructor(new[] { typeof(string) });
5152
return ctor.Invoke(new object[] { this.repositoryName }) as Instance;

SharpRepository.Ioc.StructureMap/Factories/DoubleKey.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ public override Instance CloseType(Type[] types)
4444
{
4545
var instanceType = typeof(RepositoryInstance<,,>).MakeGenericType(types);
4646

47-
if (this.configuration != null) {
48-
return Activator.CreateInstance(instanceType,this.configuration, this.repositoryName) as Instance;
47+
if (this.configuration != null) {
48+
var ctor = instanceType.GetConstructor(new[] { typeof(ISharpRepositoryConfiguration) });
49+
return ctor.Invoke(new object[] { this.configuration }) as Instance;
4950
} else {
5051
var ctor = instanceType.GetConstructor(new[] { typeof(string) });
5152
return ctor.Invoke(new object[] { this.repositoryName }) as Instance;

SharpRepository.Ioc.StructureMap/Factories/NoKey.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ public override Instance CloseType(Type[] types)
4444
{
4545
var instanceType = typeof(RepositoryInstance<>).MakeGenericType(types);
4646

47-
if (this.configuration != null) {
48-
return Activator.CreateInstance(instanceType,this.configuration, this.repositoryName) as Instance;
47+
if (this.configuration != null) {
48+
var ctor = instanceType.GetConstructor(new[] { typeof(ISharpRepositoryConfiguration), typeof(string) });
49+
return ctor.Invoke(new object[] { this.configuration }) as Instance;
4950
} else {
5051
var ctor = instanceType.GetConstructor(new[] { typeof(string) });
5152
return ctor.Invoke(new object[] { this.repositoryName }) as Instance;

SharpRepository.Ioc.StructureMap/Factories/SingleKey.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ public override Instance CloseType(Type[] types)
4848

4949
if (this.configuration != null)
5050
{
51-
return Activator.CreateInstance(instanceType, this.configuration, this.repositoryName) as Instance;
51+
var ctor = instanceType.GetConstructor(new[] { typeof(ISharpRepositoryConfiguration) });
52+
return ctor.Invoke(new object[] { this.configuration }) as Instance;
5253
}
5354
else {
5455
var ctor = instanceType.GetConstructor(new[] { typeof(string) });

SharpRepository.Ioc.StructureMap/Factories/TripleKey.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ public override Instance CloseType(Type[] types)
4444
{
4545
var instanceType = typeof(RepositoryInstance<,,,>).MakeGenericType(types);
4646

47-
if (this.configuration != null) {
48-
return Activator.CreateInstance(instanceType,this.configuration, this.repositoryName) as Instance;
47+
if (this.configuration != null) {
48+
var ctor = instanceType.GetConstructor(new[] { typeof(ISharpRepositoryConfiguration) });
49+
return ctor.Invoke(new object[] { this.configuration }) as Instance;
4950
} else {
5051
var ctor = instanceType.GetConstructor(new[] { typeof(string) });
5152
return ctor.Invoke(new object[] { this.repositoryName }) as Instance;

SharpRepository.Ioc.StructureMap/SharpRepository.Ioc.StructureMap.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353
<Compile Include="Factories\SingleKey.cs" />
5454
<Compile Include="Factories\NoKey.cs" />
5555
<Compile Include="Properties\AssemblyInfo.cs" />
56-
<Compile Include="StructureMapDependencyResolver.cs" />
5756
<Compile Include="StructureMapExtensions.cs" />
57+
<Compile Include="StructureMapRepositoryDependencyResolver.cs" />
5858
</ItemGroup>
5959
<ItemGroup>
6060
<ProjectReference Include="..\SharpRepository.Repository\SharpRepository.Repository.csproj">

SharpRepository.Ioc.StructureMap/StructureMapDependencyResolver.cs renamed to SharpRepository.Ioc.StructureMap/StructureMapRepositoryDependencyResolver.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
namespace SharpRepository.Ioc.StructureMap
66
{
7-
public class StructureMapDependencyResolver : BaseRepositoryDependencyResolver
7+
public class StructureMapRepositoryDependencyResolver : BaseRepositoryDependencyResolver
88
{
99
private readonly IContainer _container;
10-
public StructureMapDependencyResolver(IContainer container)
10+
public StructureMapRepositoryDependencyResolver(IContainer container)
1111
{
1212
_container = container;
1313
}

SharpRepository.Tests.Integration/Spikes/RepositoryDependencySpikes.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void Setup()
3434
x.ForRepositoriesUseSharpRepository();
3535
});
3636

37-
RepositoryDependencyResolver.SetDependencyResolver(new StructureMapDependencyResolver(container));
37+
RepositoryDependencyResolver.SetDependencyResolver(new StructureMapRepositoryDependencyResolver(container));
3838
}
3939

4040
[Test]

0 commit comments

Comments
 (0)