Comments (2)
I think we could definitely improve on the examples in the docs. Looks like it's pretty light in there.
For your immediate issue, you'll notice in the CombinationalWeakTypedAttributeScenarioTestFixture
that the thing being resolved is an interface, not a class/attribute:
[Fact]
public void Validate_wireup_of_generic_attributes_to_strongly_typed_metadata_on_resolve()
{
// arrange
var builder = new ContainerBuilder();
builder.RegisterMetadataRegistrationSources();
builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
.As<ICombinationalWeakTypedScenario>()
.WithAttributedMetadata();
// act
var items = builder.Build().Resolve<IEnumerable<Lazy<ICombinationalWeakTypedScenario, ICombinationalWeakTypedScenarioMetadata>>>();
// assert
Assert.Single(items);
Assert.Single(items.Where(p => p.Metadata.Name == "Hello"));
Assert.Single(items.Where(p => p.Metadata.Age == 42));
}
...and that interface looks like...
public interface ICombinationalWeakTypedScenarioMetadata
{
int Age { get; }
string Name { get; }
}
The interface is pretty important because it means Autofac can use the magic of MEF to get a strongly typed view over the metadata.
If you use a class rather than an interface, the metadata registration sources won't handle it and it falls back to the default Autofac view provider which is where you're getting that exception. The default provider basically calls new
on the type and tries to set properties, which is why adding the parameterless constructor fixes things up.
But, I agree, we could probably clean up the metadata docs a bit to bring it together better. There's nothing in there about metadata views and I think in general the doc could probably just be tightened up a bit to tie the concepts all together. Trying to pick up various bits from each section and put them all together is a challenge.
from documentation.
Thanks for the info @tillig, that's helpful to know. The error messages from autofac or elsewhere in the stack are sometimes a bit obtuse on the underlying issue or solution, so seeing it laid out in your example is helpful.
I was definitely trying to avoid having to create an interface for the metadata class in my scenario if possible, so that's probably leading me to some of the troubles. The parameterless constructor helped in my test scenario, but didn't seem to work in my practical example using a similar setup for some reason. Still wasn't able to figure that out, depending on tweaks I did it seemed to either look for the dictionary based constructor or throw some other exception outside of autofac I believe.
from documentation.
Related Issues (20)
- log4net.rst is broken HOT 2
- Update API docs for v6 HOT 2
- Clarify delegate factory docs with more commentary
- Incorrect usage of Owned<> in per-request scope example HOT 1
- Update docs to include RegisterAssemblyOpenGenericTypes HOT 1
- Clarify which properties are auto-wired
- Service resolution algorithm should be documented HOT 4
- Potential opportunity to simplify Startup.cs config in docs' Application Integration's ASP.NET Core 3.x section HOT 3
- Latest version as number HOT 7
- Add Azure Functions integration guide HOT 1
- Document Enhancement [Code snippet not working]
- Is the important part of the IAsyncDisposable section in the disposal.rst still true? HOT 4
- Document difference of behavior that can be observed when using MS IServiceProviderFactory vs AutofacServiceProviderFactory HOT 1
- Docs for `IConstructorSelector` optimization
- More middleware examples
- Broken links in upgrade documentation HOT 1
- Please add good getting started for single program template .NET 6 project HOT 6
- The layout seems completely broken. HOT 2
- Extend ASP.NET Core Integration documentation to reflect the parameter binding changes made in .NET 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from documentation.