Closed GoogleCodeExporter closed 8 years ago
As a workaround, you can use the following PropertiesAutowired_WithEnums
extension method instead of PropertiesAutowired:
public static IRegistrationBuilder<TLimit, TActivatorData, TRegistrationStyle> PropertiesAutowired_WithEnums<TLimit, TActivatorData, TRegistrationStyle>(this IRegistrationBuilder<TLimit, TActivatorData, TRegistrationStyle> This)
{
This.PropertiesAutowired();
This.OnActivated(e =>
{
var props = e.Instance.GetType().GetProperties();
foreach (var oneProp in props)
{
if (oneProp.CanWrite && oneProp.PropertyType.IsEnum)
{
if(e.Context.IsRegistered(oneProp.PropertyType))
{
var enumValue = e.Context.Resolve(oneProp.PropertyType);
oneProp.SetValue(e.Instance, enumValue, null);
}
}
}
});
return This;
}
Original comment by tahir.ah...@gmail.com
on 24 May 2011 at 2:31
Thanks for raising this. The behaviour is by design, but the original exclusion
of value types from autowiring was possibly a premature optimisation. I can't
see any harm in removing the restriction.
Cheers,
Nick
Original comment by nicholas...@gmail.com
on 15 Jun 2011 at 10:09
Auto-wiring (and registrations for that matter) don't really make any sense for
any value type other than the enum. Having said that, I don't see a reason to
disable any type to be auto-wired - if people want to shoot themselves in the
foot by registering and auto-wiring int's and long's, who are we to stop them?
:)
Tahir
Original comment by tahir.ah...@gmail.com
on 15 Jun 2011 at 12:29
:) to minimise risk I've enabled this for enums only right now, let's leave
other value types for consideration in the future.
Original comment by nicholas...@gmail.com
on 3 Jul 2011 at 5:37
Thank you!
Original comment by tahir.ah...@gmail.com
on 3 Jul 2011 at 11:21
Original issue reported on code.google.com by
tahir.ah...@gmail.com
on 24 May 2011 at 1:02