OrchardCore icon indicating copy to clipboard operation
OrchardCore copied to clipboard

Cleanup markdown by moving models to the Abstractions project

Open MikeAlhayek opened this issue 3 years ago • 18 comments

Fix #11698

MikeAlhayek avatar May 13 '22 20:05 MikeAlhayek

Can anyone give me proper reason why we need this before we merge? https://github.com/OrchardCMS/OrchardCore/issues/11698#issuecomment-1179579984

hishamco avatar Jul 09 '22 17:07 hishamco

If you are creating an abstraction or core project where you define your models, while the model is using MarkdownField, there is no need to add dependency on the OC.Markdown on the core or abstraction model .

for example, I want to create a custom model in my project called xyz. I created xyz.Core or xyz.Abstraction where I keep a model that uses MarkdownField. In this case I won’t have to depend on OC.Markdown, instead all I would add is a reference to the abstractions

MikeAlhayek avatar Jul 09 '22 18:07 MikeAlhayek

Still I didn't understand, when you need a MarkdownField you should reference it's project. If that's the case HtmlField should have an abstractions

Again I didn't see a value unless the implementation should be different for a particular abstractions project

hishamco avatar Jul 09 '22 20:07 hishamco

Let me try to explain it in code, I hope this helps. In CustomModule.Abstraction project I want to add the following modal

public class SomeModel
{
      public MarkdownField Content { get; set; }
}

For this to work currently, I would have to add dependency to OrchardCore.Markdown on my CustomModule.Abstraction which isn't needed here because CustomModule.Abstraction may not need to depend on the CMS or for the simple fact that my abstraction project does not need OrchardCore.Markdown. If we move the MarkdownField to OrchardCore.Markdown.Abstractions then CustomModule.Abstraction would only depend on OrchardCore.Markdown.Abstractions.

MikeAlhayek avatar Jul 09 '22 21:07 MikeAlhayek

I got what you want to explain, but this something special in your case, If we want plan to accept this, what about HtmlField and other fields?

hishamco avatar Jul 10 '22 01:07 hishamco

IMO, I think all field ContentFields, Markdown, MediaField, HtmlField all should be moved to their abstraction project. All these models and their settings can be used in Abstraction and Core project.

MikeAlhayek avatar Jul 10 '22 02:07 MikeAlhayek

If it's like that do we really treat fields as abstractions? Which I don't think so, let us hear @sebastienros thought about this one?

hishamco avatar Jul 12 '22 14:07 hishamco

It is just about reusability/extensibility. If you want to use a NumericField in a different module right now you need to reference the entire OrchardCore.ContentField project which is wrong to me. And yes, ContentFields needs to be reusable.

Skrypt avatar Jul 12 '22 14:07 Skrypt

It is just about reusability/extensibility.

Agree, but there many things we should think about. I remembered two or three times I required to reference a module in Orchard Core Contrib (OCC) because OC encapsulate many of the types and services inside some modules. Hope to find time I mention some cases

hishamco avatar Jul 12 '22 14:07 hishamco

Yes, I agree with you @hishamco but it is part of the tasks that we need to do to make OC more like a Framework. And these tasks will take time. It is probably better to do the work progressively.

Skrypt avatar Jul 12 '22 15:07 Skrypt

@CrestApps just one question if we use something like this

public MarkdownField Content { get; set; }

How the UI will be generated for such field in the referenced module?!!

hishamco avatar Jul 14 '22 00:07 hishamco

@hishamco the field will be added to a model to a CustomModule.Abstraction project. So it will not need to render the field. This would just be part of abstraction/core project. The module that would consume this project would then need to depend on the Markdown feature. The idea here is structuring the code is much reusable way.

MikeAlhayek avatar Jul 14 '22 02:07 MikeAlhayek

This means any custom markdown module need to do all the heavt lifting instead of reusing the work that done in OC.Markdown

hishamco avatar Jul 14 '22 14:07 hishamco

I don’t think I follow you. We do this just to abstract away the code. The module will still be referenced by other modules when needed.

MikeAlhayek avatar Jul 14 '22 15:07 MikeAlhayek

The module will still be referenced by other modules when needed.

This could be done outside OC but not inside ;)

hishamco avatar Jul 14 '22 15:07 hishamco

I am not sure I follow you. I guess the question is, do you see an issue with abstracting the model and the setting?

MikeAlhayek avatar Jul 14 '22 15:07 MikeAlhayek

I guess the question is, do you see an issue with abstracting the model and the setting?

Nope, but wondering while any field should has its own UI, so is that mean any implementation should has to redefine the UI. I never mind if all the guys are agreed with the idea

hishamco avatar Jul 14 '22 15:07 hishamco

@hishamco another good reason for this is to prevent the use of internal classes.

For example, if you look at the Taxonomies migration you'll see internal classes AliasPartSettings and AutoroutePartSettings created as shadow to the actual settings class, just because AliasPartSettings and AutoroutePartSettings are not part of the OrchardCore.Alias.Abstractions or OrchardCore.Autoroute.Core. The problem with creating internal models like that is what if the actual setting model change? I see no reason for doing such an approach “creating shadows classes” where we can simply move the model and setting into the abstraction class and everything will just fall into place as it should.

The Markdown and other modules falls into the same problem as TaxonomiesMigration. In fact settings and models classes are already part of many abstraction projects in OC. So at the very least there is a consistency problem with not moving the model and the settings into the abstraction project.

I think abstraction project should contain, interfaces, core/domain models including setting models.

Core project will include implementations and services and will depend on abstraction project. Then, the CMS module project will have everything else and will depend on the core project.

MikeAlhayek avatar Jul 19 '22 01:07 MikeAlhayek