Why is my content part not recognized in Orchard Core? - Orchard Nuggets
You have implemented your
MyAwesomePart but you cannot attach it to your content type using the dashboard because it's not showing in the Content Parts list (Content -> Content Definition -> Content Parts)?
The most possible reason for this that you haven't registered your implementation in the service container. To register your class in the service container head to the Startup.cs file of your module and in the
ConfigureServices method add the following line:
But if you are using the RC1 version of Orchard Core or newer you can use the
AddContentPart extension method, where you just only need to provide your content part:
AddContentPart and the
AddContentField (that you can use to register your fields) can be found in the OrchardCore.ContentManagement namespace.
Another recommendation is to use the Part suffix when naming your class or cs file that contains your custom part. Don't forget to put it in a Models folder to follow the recommendation of the MVC (model-view-controller) software design pattern.
For more information about registering your Part check out the Startup.cs file of our Orchard Core Training Demo module, where we registered the
PersonPart in the service container. We also mentioned the new way of registering ContentParts and ContentFields in this post of our This week in Orchard series.