Create a better way for registering package resources through C# #12054
Replies: 1 comment 1 reply
-
Just to say there is already a PackageManifest class used in the Packaging Services, and that can be used programmatically to add manifest to at boot time. you can add a
and you append this in the composer:
(i have some of this sitting in branch for a RCL version of uSync) It would of course be WAY better for this to be an interface that was discovered, although i am not sure what the current stance on Type discovery at boot time is (i think its considered slow). but I think And it would certainly get my vote if we could also include lang files and/or language entries this way. |
Beta Was this translation helpful? Give feedback.
-
Create a better way for registering package resources through C#
Today Umbraco provides a few different ways for registering resources and components.
Many resources can be registered by creating a
package.manifest
file - eg. CSS and JavaScript assets, but also things like property editors, dashboards, content apps or similar. This may be great for smaller packages, but not super flexibly for larger and more complex packages.Most resources and components can also be registered from C#, but with a few different approaches for doing so - some not super friendly. For instance with backoffice assets, these can be registered in the example below:
So to add a new CSS asset, I had to create the
ModelsBuilderCssAsset
class implementing theIAssetFile
interface - eg. like:This seems like a bit more work than should be necessary. #11308 is an open PR that also works on improving the developer experience.
umbraco/rfcs#27 also proposes creating a JavaScript first approach to registering components in Umbraco. Both as a package developer and a solution implementer, I feel this is a step in the wrong direction (reasons for thinking this are well describe in the RFC).
So my proposal is to introduce a new interface serving as a C# euquivalent of the
package.manifest
file. It oculd be defined like in the example below:Umbraco could automatically look for classes implementing the
IPackageManifest
interface, and make sure the instances are properly registered with Umbraco. For starters, the interface describes the name and version of the package, along with theAllowPackageTelemetry
property recently introduced forpackage.manifest
.The
GetAssets
method could be used for returning the CSS and JavaScript assets that should be loaded for this particular package. IMO this would make setting this up much easier that it is today.Registering a NuGet package so that it shows up in the Packages section isn't super friendly either - eg. via a package migration. With the
IPackageManifest
interface, it could also mean that instances of this interface are automatically shown in the list of installed packages - maybe even with more information than is shown today (eg. package version, package author information etc.).XML files are also a bit old school, so the
IPackageManifest
interface could likely describe a method that would return all the keys/phrases for a package. This would introduce an "API" for registering translations through C# like Jason suggests.So to sum this up, my the proposal is that the
IPackageManifest
interface could be the preferred approach for registering resources and components via C#. The interface should likely have lots of other options as well - or perhaps it should be an abstract base class instead so it's easier to later introduce new options without it resulting in breaking changes.Beta Was this translation helpful? Give feedback.
All reactions