Problem Statement
It's unclear from the metadata docs on how to use an attribute that's created outside the filtering scenario and instead to lookup values on the metadata either during or before resolution.
For instance modifying the WeakTypedAttributeScenarioTestFixture to demonstrate what I was trying:
// arrange
var builder = new ContainerBuilder();
builder.RegisterModule<AttributedMetadataModule>();
builder.RegisterType<CombinationalWeakTypedScenario>().As<ICombinationalWeakTypedScenario>();
// act
var items = builder.Build().Resolve<IEnumerable<Lazy<ICombinationalWeakTypedScenario, CombinationalWeakAgeMetadataAttribute>>>();
// assert
Assert.Single(items);
Assert.Single(items.Where(p => p.Metadata.Age == 42));
But this leads to a Autofac.Core.DependencyResolutionException : The type 'CombinationalWeakAgeMetadataAttribute' cannot be used as a metadata view. A metadata view must be a concrete class with a parameterless or dictionary constructor. error.
If I add a parameterless constructor to the type, then it appears to work in the test project (though I'm having trouble making this work in my own project with an enum instead of an int/string).
Anyway, it'd be great to see more examples for different setups in the documentation for using these types of more strongly-typed custom attributes.
Desired Solution
More guidance on using strongly-typed custom metadata within autofac. Especially around metadata lookup before resolution, if possible?
Problem Statement
It's unclear from the metadata docs on how to use an attribute that's created outside the filtering scenario and instead to lookup values on the metadata either during or before resolution.
For instance modifying the WeakTypedAttributeScenarioTestFixture to demonstrate what I was trying:
But this leads to a
Autofac.Core.DependencyResolutionException : The type 'CombinationalWeakAgeMetadataAttribute' cannot be used as a metadata view. A metadata view must be a concrete class with a parameterless or dictionary constructor.error.If I add a parameterless constructor to the type, then it appears to work in the test project (though I'm having trouble making this work in my own project with an
enuminstead of an int/string).Anyway, it'd be great to see more examples for different setups in the documentation for using these types of more strongly-typed custom attributes.
Desired Solution
More guidance on using strongly-typed custom metadata within autofac. Especially around metadata lookup before resolution, if possible?