-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tightens up finding the right constructor in an expression. Closes GH…
- Loading branch information
1 parent
b86c0b7
commit f1954f0
Showing
5 changed files
with
110 additions
and
3 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
src/StructureMap.Testing/Bugs/Bug_322_class_with_multiple_constructors.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,96 @@ | ||
using System.Diagnostics; | ||
using NUnit.Framework; | ||
using StructureMap.Graph; | ||
|
||
namespace StructureMap.Testing.Bugs | ||
{ | ||
[TestFixture] | ||
public class Bug_322_class_with_multiple_constructors | ||
{ | ||
[Test] | ||
public void reproduce() | ||
{ | ||
var anotherDependency = new AnotherDependency(); | ||
|
||
var container = new Container(x => | ||
{ | ||
x.Scan(s => | ||
{ | ||
s.TheCallingAssembly(); | ||
s.AssembliesFromApplicationBaseDirectory(); | ||
s.WithDefaultConventions(); | ||
}); | ||
x.For<IActivityService>().Singleton(); | ||
x.ForConcreteType<ClassWithTwoConstructors>() | ||
.Configure.SelectConstructor(() => new ClassWithTwoConstructors(new AnotherDependency())) | ||
.Ctor<AnotherDependency>().Is(anotherDependency); | ||
//.Ctor<AnotherDependency>("anotherDependency").Is(anotherDependency); | ||
}); | ||
|
||
container.GetInstance<MainService>() | ||
.AnotherDependency.AnotherDependency.ShouldBeTheSameAs(anotherDependency); | ||
} | ||
|
||
|
||
public class AnotherDependency | ||
{ | ||
public AnotherDependency() | ||
{ | ||
} | ||
} | ||
|
||
public class ClassWithTwoConstructors | ||
{ | ||
private readonly AnotherDependency _anotherDependency; | ||
|
||
|
||
public ClassWithTwoConstructors(int age, string name) | ||
{ | ||
|
||
} | ||
|
||
public ClassWithTwoConstructors(AnotherDependency anotherDependency) | ||
{ | ||
_anotherDependency = anotherDependency; | ||
} | ||
|
||
public AnotherDependency AnotherDependency | ||
{ | ||
get { return _anotherDependency; } | ||
} | ||
} | ||
|
||
public interface IStoryService { } | ||
|
||
public class StoryService : IStoryService | ||
{ | ||
} | ||
|
||
public interface IActivityService { } | ||
public class ActivityService : IActivityService { } | ||
|
||
public class MainService | ||
{ | ||
private readonly ClassWithTwoConstructors _anotherDependency; | ||
|
||
public MainService(IStoryService storyService, | ||
ClassWithTwoConstructors anotherDependency) | ||
{ | ||
_anotherDependency = anotherDependency; | ||
} | ||
|
||
public ClassWithTwoConstructors AnotherDependency | ||
{ | ||
get { return _anotherDependency; } | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
} |
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