I am trying to build a module with the following in a migration:
public class XyzzyPartRecord : ContentPartRecord
{
public virtual string Plugh { get; set; }
}
public class XyzzyPart : ContentPart<XyzzyPartRecord>
{
public string Plugh {
get { return Retrieve( r => r.Plugh ); }
set { Store( r => r.Plugh, value ); }
}
}
public int Create() {
SchemaBuilder.CreateTable( "XyzzyPartRecord", table => table
.ContentPartRecord()
.Column<string>( "Plugh" )
);
ContentDefinitionManager.AlterPartDefinition( "XyzzyPart", cfg => cfg
.WithDescription( "XyzzyPart" ) );
ContentDefinitionManager.AlterTypeDefinition( "XyzzyItem", cfg => cfg
.WithPart( "XyzzyPart" )
);
return 1;
}
When accessing an XyzzyItem, there is no XyzzyPart in the Parts collection. Instead there is a ContentPart.
How do I get my Content Part to allow it to be added to a Content Item's Parts collection?
I had neglected to create either a Driver or a Handler for my part. Once those were in place my code worked as expected.
namespace MyProject.Drivers {
public class XyzzyPartDriver : ContentPartDriver<XyzzyPart> {
protected override DriverResult Display( XyzzyPart part, string displayType, dynamic shapeHelper ) {
return ContentShape( "Parts_Xyzzy",
() => shapeHelper.Parts_Xyzzy(
Xyzzy: part ) );
}
}
}
namespace MyProject.Handlers {
public class XyzzyPartHandler : ContentHandler {
public XyzzyPartHandler( IRepository<XyzzyPartRecord> repository ) {
Filters.Add( StorageFilter.For( repository ) );
}
}
}