question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using a different base component class

See original GitHub issue

MvvmComponentBase inherits from ComponentBase. What’s the best practice if we want to use a different base component class, say OwningComponentBase or AbpComponentBase as we are using the ABP framework, yet still want to keep the functionalities provided by MvvmComponentBase?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:15 (15 by maintainers)

github_iconTop GitHub Comments

3reactions
klemmchrcommented, Jun 7, 2021

Since we now got code generators in .NET I’m not a huge fan of Fody weavers any more. They served their purpose, but the built in source generators should do the job. The docs cover our use case.

My plan would be to ship that source generator too (either in a separate NuGet package or directly with the main one). This way, any integration would happen by defining a partial class with a given attribute that would be picked up by the source generator.

1reaction
hillincommented, Sep 13, 2021

So the problem here is misusing of the ISyntaxContextReceiver. For each compilation unit (assembly), only one instance of each ISyntaxContextReceiver is created and they are being reused again and again, for all GeneratorSyntaxContexts.

In the MvvmBlazor project, there are 3 classes annotated with the MvvmComponentAttribute. The MvvmSyntaxReceiver visits them one by one, and only keeps the ComponentClass and ComponentSymbol values for the last of them, which I see is MvvmOwningComponentBase. Therefore you can see the code was only generated for that last class, but not for other classes, e.g. MvvmComponentBase<T>, which is used in the sample project and thus it did not compile.

With that fixed, some minor issues expose, like MvvmComponentBase<T> and MvvmComponentBase has the same identifier, but you have to generate their code to different files, and the generic source template missed the partial modifier etc.

I’ve fixed those problems here, the solution now compiles, except for a test project which I did not bother to look: https://github.com/klemmchr/MvvmBlazor/pull/54

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Extend Classes with Angular Component Inheritance
Using class inheritance in TypeScript, you can declare a base component that ... Let's start by using the Angular CLI to create a...
Read more >
How to inherit a component in Angular and reuse its template
You may override Base component's CSS by adding multiple CSS files too. ... You create a BaseComponent class, and do ChildComponent extends BaseComponent...
Read more >
How to extend / inherit components? - angular
2 - Base Component with @Component decorator: ... more components contains shared logic: use a service or even create a new typescript class...
Read more >
All about that BaseComponent
I find in most large projects you end up having some reusable functionality that fits perfectly in a base class. In a future...
Read more >
Component Inheritance in Angular - Bits and Pieces
Using inheritance in TypeScript we can use the Parent-Child design to delegate the common code to a base class and let other components...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found