Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Uses SM for ctor injection on property groups too #14

Open
wants to merge 2 commits into from

1 participant

This page is out of date. Refresh to see the latest.
View
13 PageTypeBuilder.Activation.StructureMap.Tests/CreateInstanceTests.cs
@@ -21,6 +21,19 @@ public void CreateInstance_UsesInjectedContainerToCreateInstanceOfRequestedType(
}
[Fact]
+ public void CreateInstance_UsesInjectedContainerToCreateInstanceOfPropertyGroupInRequestedType()
+ {
+ string expectedCtorParam = Guid.NewGuid().ToString();
+ Mock<IContainer> fakeContainer = new Mock<IContainer>();
+ fakeContainer.Setup(container => container.GetInstance(typeof(string))).Returns(expectedCtorParam);
+ StructureMapTypedPageActivator activator = new StructureMapTypedPageActivator(fakeContainer.Object);
+
+ PageTypeThatHasPropertyGroup pageData = (PageTypeThatHasPropertyGroup)activator.CreateAndPopulateTypedInstance(new PageTypeThatHasPropertyGroup(), typeof(PageTypeThatHasPropertyGroup));
+
+ Assert.Equal<string>(expectedCtorParam, pageData.PropertyGroup.Injected);
+ }
+
+ [Fact]
public void CreateInstance_ThrowsPageTypeBuilderExceptionForTypeWithNoPublicCtor()
{
StructureMapTypedPageActivator activator = new StructureMapTypedPageActivator(null);
View
2  ...uilder.Activation.StructureMap.Tests/PageTypeBuilder.Activation.StructureMap.Tests.csproj
@@ -92,9 +92,11 @@
<Link>Properties\SolutionInfo.cs</Link>
</Compile>
<Compile Include="CreateInstanceTests.cs" />
+ <Compile Include="PageTypeThatHasPropertyGroup.cs" />
<Compile Include="PageTypeWithNoPublicConstructor.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="PageTypeWithStringCtorParam.cs" />
+ <Compile Include="PropertyGroupWithStringCtorParam.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PageTypeBuilder.Activation.StructureMap\PageTypeBuilder.Activation.StructureMap.csproj">
View
8 PageTypeBuilder.Activation.StructureMap.Tests/PageTypeThatHasPropertyGroup.cs
@@ -0,0 +1,8 @@
+namespace PageTypeBuilder.Activation.StructureMap.Tests
+{
+ public class PageTypeThatHasPropertyGroup : TypedPageData
+ {
+ [PageTypePropertyGroup]
+ public virtual PropertyGroupWithStringCtorParam PropertyGroup { get; set; }
+ }
+}
View
11 PageTypeBuilder.Activation.StructureMap.Tests/PropertyGroupWithStringCtorParam.cs
@@ -0,0 +1,11 @@
+namespace PageTypeBuilder.Activation.StructureMap.Tests
+{
+ public class PropertyGroupWithStringCtorParam : PageTypePropertyGroup
+ {
+ public string Injected;
+ public PropertyGroupWithStringCtorParam(string someDependency)
+ {
+ Injected = someDependency;
+ }
+ }
+}
View
9 PageTypeBuilder.Activation.StructureMap/StructureMapTypedPageActivator.cs
@@ -24,6 +24,15 @@ public override TypedPageData CreateInstance(Type typedType)
return base.CreateInstance(typedType, ctorParameters);
}
+ public override PageTypePropertyGroup CreatePropertyGroupInstance(Type typedType)
+ {
+ ParameterInfo[] expectedParameters = GetCtorParameters(typedType);
+
+ object[] ctorParameters = GetResolvedParameters(expectedParameters);
+
+ return base.CreatePropertyGroupInstance(typedType, ctorParameters);
+ }
+
private static ParameterInfo[] GetCtorParameters(Type typedType)
{
ConstructorInfo constructor = GetConstructorWithMostParameters(typedType);
View
3  PageTypeBuilder/TypedPageData.cs
@@ -114,9 +114,8 @@ public new PageData CreateWritableClone()
{
PageData page = base.CreateWritableClone();
IEnumerable<PropertyInfo> properties = page.GetType().GetPageTypePropertyGroupProperties();
- new TypedPageActivator().CreateAndPopulateNestedPropertyGroupInstances(page as TypedPageData, page, properties, string.Empty);
+ PageTypeResolver.Instance.Activator.CreateAndPopulateNestedPropertyGroupInstances(page as TypedPageData, page, properties, string.Empty);
return page;
}
-
}
}
Something went wrong with that request. Please try again.