I downloaded the source and had a quick look at this myself.
The problem with internal constructors seems to limited to a few
issues with type rules and with making the internals of my assemblies
visible to StructureMap's dynamically emitted assemblies.
I was able to patch things up so they work for my simple test cases,
but I would appreciate Jeremy's opinion on whether this is something
that will be fixed in future versions of StructureMap.
Here is what I did:
Rewrote StructureMap.Graph.Constructor.GetGreediestConstructor() to
also return internal constructors:
public static ConstructorInfo GetGreediestConstructor(Type
pluggedType)
{
ConstructorInfo returnValue = null;
foreach (ConstructorInfo constructor in
pluggedType.GetConstructors(BindingFlags.Public |
BindingFlags.NonPublic | BindingFlags.Instance))
{
if (constructor.IsPrivate && !constructor.IsAssembly)
continue;
if (returnValue == null)
{
returnValue = constructor;
}
else if (constructor.GetParameters().Length >
returnValue.GetParameters().Length)
{
returnValue = constructor;
}
}
return returnValue;
}
And the same for TypeRules.noPublicConstructors():
private static bool noPublicOrInternalConstructors(Type pluggedType)
{
var constructors = pluggedType.GetConstructors
(BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Instance);
return !constructors.Any(c => (c.IsPublic ||
c.IsAssembly));
}
The second issue is more tricky - making internals visible to the
dynamic instance builder assemblies.
As far as I can tell, the only way to do this is if I know the name(s)
of the dynamically emitted assemblies in advance, so that I can use
the [assembly:InternalsVisibleTo] attribute.
StructureMap.Emitting.InstanceBuilderAssembly uses a dynamically
generated GUID as part of the assembly name, so this is not possible
with the current implementation.
The dynamic assembly also needs to have the PublicKey and
PublicKeyToken properties set to valid values.
So by using a well known name for the dynamic assembly and setting the
PublicKey to StructureMap's public key I was able to make things work
for me, but of course I don't know how this will impact the rest of
the code base.
Again, I would appreciate Jeremy's thoughts on whether the possibility
of using internal constructors is something that will find its way
into future versions of StructureMap.
Regards,
Christian Lundestad
On Jul 10, 2:55 pm, Christian Lundestad <
christ...@lundestad.com>
wrote:
> StructureMap.Configuration.DSL.ExpressionValidator.ValidateExpression.IntoPluginType
> (Type pluginType)
> at
> StructureMap.Configuration.DSL.Expressions.CreatePluginFamilyExpression`1.TheDefaultIsConcreteType