Тёмный

How to Use Code Behind for Blazor Components | 2 Solutions 

Claudio Bernasconi
Подписаться 18 тыс.
Просмотров 5 тыс.
50% 1

Опубликовано:

 

28 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 17   
@ClaudioBernasconi
@ClaudioBernasconi Год назад
What approach of separating the template and the interaction code for Blazor components do you like the most? Do you always keep all the code within the same razor file? 🙂
@EricKing
@EricKing Год назад
I initially disliked having the code and the markup in the same file, being used to separate files for many years. But, having decided to give the singe-file approach a try a few years ago, I actually much prefer keeping the code and the markup together now. The main reason is that doing so encourages keeping the UI component code itself as simple as possible, delegating complex work to separate non-component classes where they can be isolated and reasoned about and tested easier. If I find my UI component file to be getting large and unwieldy, that's a sign that I should take a closer look at the component to see how I can simplify it by maybe breaking it down into smaller components or possibly extracting the complex logic into a separate class or classes decoupled from the component. IMO, a well-designed component is much easier to read when the code and the markup are together.
@RajK09
@RajK09 4 месяца назад
I was looking for same content and your video played automatically. Thank you for the content.
@ClaudioBernasconi
@ClaudioBernasconi 4 месяца назад
Thanks for your kind comment and thanks for watching.
@Codewrinkles
@Codewrinkles Год назад
I actually like this video very much. Very condensed and cllear information. And very nice editing.
@ClaudioBernasconi
@ClaudioBernasconi Год назад
Thanks a lot. That's very kind of you and means a lot to me. I try to make every video a little bit better than the previous. 😎
@tacticoolrick5562
@tacticoolrick5562 Год назад
Since your razor component inherts from the base component, can you then override in your @code block or in your razor.cs file?
@ClaudioBernasconi
@ClaudioBernasconi Год назад
I'm not sure I understand your question, but I give it my best to provide a helpful answer here. Every Blazor/Razor component inherits from the ComponentBase class. You can use either of the inheritance definition models, but you cannot mix and match. I would not advise building a component tree. I would always build components based on the ComponentBase class. I do not have any experience with components inheriting from each other and overriding functionality. In my opinion, this adds too much complexity to justify it. I'd rather extract code into another class to share code between two Blazor components. I hope that helps answer your question. Otherwise, feel free to provide a link to a GitHub repo or a Gist so we can discuss more hands-on.
@tacticoolrick5562
@tacticoolrick5562 Год назад
@@ClaudioBernasconi - oh let me rephrase, in your video you created a component base class, call it MyComponentBase, and then used the @inherit MyComponentBase in your blazor component. Can you then override MyComponentBase methods, from your blazor page, if you needed to?
@netrixtechie
@netrixtechie Год назад
Good work bro, we reaaly appreciate your effor. PLS CAN HELP WITH USING CUSTOM HTML TEMPLATES IN BLAZOR ASIDE THE BOILER TEMPLATE FROM MICROSOFT. Plsssss
@krccmsitp2884
@krccmsitp2884 5 месяцев назад
4:45 Does Blazor also support regular constructor injection we use in MVC or Controller API?
@ClaudioBernasconi
@ClaudioBernasconi 5 месяцев назад
Yes, it's possible with one of the "code-behind" approaches: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-kjWsGlpYGmQ.html
@krccmsitp2884
@krccmsitp2884 5 месяцев назад
@@ClaudioBernasconi great, thanks
@TebohoPhofu
@TebohoPhofu Год назад
For the code-behind, is it possible to inject _todoService using the Constructer instead of using the Inject Attribute and make the TodoSerivce a property?
@ClaudioBernasconi
@ClaudioBernasconi Год назад
Great question! It doesn't work for me. I could only speculate why it's not possible, but I'm not the right person to provide that information. As far as I can tell, only parameter injection works for Blazor components.
@lgmsampaio
@lgmsampaio 6 месяцев назад
I don't trust any developer that don't use Dark mode in VStudio. And you should have added "= default!;" to the declaration of your TodoService in the code behind.
@ClaudioBernasconi
@ClaudioBernasconi 6 месяцев назад
That sounds like trust issues. However, I don't judge you.
Далее
Blazor Component Communication & State Handling
7:42
LINQ's INSANE Improvements in .NET 9
11:26
Просмотров 48 тыс.
Is Blazor Better than React?
14:25
Просмотров 49 тыс.
Premature Optimization
12:39
Просмотров 810 тыс.
Creating Blazor Components the right way
24:21
Просмотров 12 тыс.
Blazor Component Life Cycle - Common Pitfalls
8:13
Просмотров 1,5 тыс.
Blazor: Why 2024 Is The Year Of Blazor 🚀
9:40
Просмотров 25 тыс.