cofoundry icon indicating copy to clipboard operation
cofoundry copied to clipboard

BlockTypes in own Project.

Open kenan-kajkus opened this issue 3 years ago • 5 comments

I can't find a way to implement blocktypes in a separate project. The reason is that we need the blocktypes in several projects.

kenan-kajkus avatar Jul 23 '21 12:07 kenan-kajkus

It's not documented yet, but you'll need to do a few things:

  1. Ensure your project is named in a way it can be picked up by DI: check the relevant section of the dependency injection docs
  2. Ensure any view files are marked as embedded resources
  3. Include a class in your project that implements IAssemblyResourceRegistration - this is just a marker class that the DI system looks for to know if it should scan your project for embedded resources.
  4. Ensure view files are located in one of the default view block type folders, or implement your own IPageBlockTypeViewLocationRegistration if you want to namespace it under a custom path to avoid conflicts. See the page block types docs for more info.

Note that with embedded resources, files in your main project will override embedded resources in the same location in dependent projects.

HeyJoel avatar Jul 23 '21 13:07 HeyJoel

I am still getting this error. Could you imagine why? image

kenan-kajkus avatar Jul 25 '21 19:07 kenan-kajkus

It looks like Cofoundry can find your block type classes, but not your view file. Do check points 2, 3 and 4 in my comments above.

I've updated the page block types sample project to include an example of placing block types in a separate project, along with a bit more detail in the readme.

HeyJoel avatar Jul 26 '21 08:07 HeyJoel

Thank you so much. I messed up the namespaces part. What a rookie mistake.

kenan-kajkus avatar Jul 26 '21 09:07 kenan-kajkus

No worries, it's more complicated than I'd like it to be and it isn't documented. I'm hopeing that the new source generators feature in .NET 6 is going to make all this a bit simpler because we can pull all this stuff in at compiletime instead of runtime, but I haven't had a chance to play around with it yet.

I'll leave this issue open as it needs documenting in the main Cofoundry docs.

HeyJoel avatar Jul 26 '21 09:07 HeyJoel