kontent-ai / sample-app-net

Sample .NET MVC web application using the Kontent.ai Delivery .NET SDK to retrieve content
https://docs.kontent.ai/tutorials/develop-apps?tech=dotnet
MIT License
19 stars 66 forks source link

Extract HTML helpers (edit mode panel, etc.) to a separate library #110

Closed xantari closed 4 years ago

xantari commented 5 years ago

Motivation

Some HTML helpers can be reused in production projects.

Proposed solution

Extract HTML helpers to a separate project: https://github.com/Kentico/kontent-aspnetcore

Outstanding:

To be considered:

petrsvihlik commented 4 years ago

Hi @xantari , thanks very much for the feedback! I guess we're talking about the HtmlHelperExtensions, right?

Could you please provide a little bit more context on:

  1. Which methods do you consider worth extracting from the .NET sample site?
  2. Do you prefer to have them as a part of this boilerplate or would you like to see them as a separate NuGet package?
  3. To make it generic enough, we'd have to strip some parts specific for the .NET sample site (such as CSS classes, etc.) - is that acceptable? Is it still worth extracting?

Additional context for the implementer:

xantari commented 4 years ago

@petrsvihlik Thanks for the response back!.

Yes I am talking about those HtmlHelperExtensions in the MVC 5 project.

The current .NET Core 3 boiler plate has a few HTML helpers ported over from the older MVC 5 template such as AssetImage.

I guess I'm just asking for the ones that are not specific to that sample site ported over. In particular the edit feature links are really helpful in that boilerplate and consumers of the .NET Core 3 sample might not understand that capability exists, so it would be helpful if it was included.

Right now only the edit link ones are the ones that I think are worth extracting if they could be made in a generic way (which I'm not sure is possible).

At the very least, if you don't want to add to the .NET Core boilerplate, perhaps the .NET Core 3 version of the Dancing Goats sample, with a link on this boilerplate readme.md to that sample so that folks understand how to implement it in their own site.

xantari commented 4 years ago

As for a nuget package, not sure about that. I kinda like the code being available to edit. And stripping the CSS classes is fine, perhaps those could be made as parameters to the function?

petrsvihlik commented 4 years ago

We'll discuss it internally and let you know :)

ewomack2000 commented 4 years ago

I copied the code over from the MVC 5 project, but it took a little adjusting. It seems to be working with the Boilerplate. The issues mostly revolved around .NET Core's configuration, so I had to find new ways to get the projectId, etc.

petrsvihlik commented 4 years ago

hi @ewomack2000 , could you please elaborate a bit more on what issues you had with the configuration? is there something that could be described better at our side?

ewomack2000 commented 4 years ago

The issues weren't huge, but they mostly revolved around getting configuration data in places that needed injection. The EditLinkHelper was using pre-Core configuration and it was called in a way that did not evoke the constructor, so I ended up passing the project id as a parameter, but that bypasses the instance call, which is something I still need to fix, but it allowed the edit panel to work. I believe that I also had to change the types for the generated HTML in the HtmlHelperExtension's "InlineElementLink" and "BlockElementEditLink" methods, because Core didn't like the MvcString type. It was more a lot of little things, but I did get it to work with .NET Core 3.0.

petrsvihlik commented 4 years ago

Thanks for the details! We'll first port the sample app to .NET Core 3 (along with the HtmlHelperExtensions) and then decide how we could extract the helpers so that they can be reused in multiple projects. Again, I appreciate your feedback - it's very helpful.

petrsvihlik commented 4 years ago

Outstanding:

To: https://github.com/Kentico/kontent-aspnetcore

petrsvihlik commented 4 years ago

Configuration

@ewomack2000 the "edit mode" code was rewritten to use tag helpers

which depend on the IEditLinkBuilder which can be injected via DI. The configuration of the mentioned service is shown in the Startup class and the final usage in the FactAboutUsViewModel.cshtml.

So the configuration should now be in line with netcore's best practices.

Extracting the code

@xantari given the number of custom CSS classes in the EditPanelTagHelper, I don't think this is a good candidate to be extracted to https://github.com/Kentico/kontent-aspnetcore. If everything was made parametrizable, it would make things unreadable and bring almost no added value. What do you think? Do you see a better way to do it?

petrsvihlik commented 4 years ago

Oh yeah, and I almost forgot - I cleaned up the readme. It should contain less fluff and more up-to-date info.

https://github.com/Kentico/kontent-sample-app-net/blob/master/README.md

xantari commented 4 years ago

Yeah those EditPanel ones are hard. I agree they probably should be left only in the dancing goat sample and not in the main nuget packages.

petrsvihlik commented 4 years ago

thanks for the confirmation @xantari ! I'm closing this issue now...let's see if we identify more stuff that could be extracted to https://github.com/Kentico/kontent-aspnetcore