blazor-redux icon indicating copy to clipboard operation
blazor-redux copied to clipboard

Question: Best alternative to inheriting base class

Open Sire opened this issue 6 years ago • 1 comments

I want to avoid using inheritance (@inherits MyAppComponent) because my pages and components often already use inheritance. (Plus we favor composition anyway right?)

Most of my pages inherit from class that inherits from BlazorComponent. Containing all the page/view functions, similar to a code-behind class in regular ASP.NET as recommended here.

I tried injecting and just instantiating the MyAppComponent(), neither works. Perhaps I'm missing something obvious @torhovland?

Sire avatar Dec 06 '18 08:12 Sire

Solved it. Inheriting from BlazorComponent isn't required, you can use it's interfaces instead. So in my code-behind classes I just inherit from this class that contains both the state component AND the BlazorComponent interfaces.

public class BlazorComponentBase : StateComponent, IComponent, IHandleEvent, IHandleAfterRender, IDisposable

I can help update the documentation if you think more will run into this problem.

Sire avatar Dec 06 '18 13:12 Sire