请注意,本站并不支持低于IE8的浏览器,为了获得最佳效果,请下载最新的浏览器,推荐下载 Chrome浏览器
欢迎光临。交流群:166852192

Welding Parts


In Orchard, when you load an existing Content Item or create a new one the first thing to be done is to initialize this object with the available Content Parts. It's interesting to understand how it's done, as it gives you more knowledge of what happens when you create your modules.
Almost everything in Orchard is happening in Content Handlers. A content handler is just an implementation of IContentHandler, and they all get called when something happens on some content. One of the methods in those content handlers is Activating, which is called when a ContentItem has to be instantiated. It gets an ActivatingContentContext as argument.
public class ActivatingContentContext {
   public string ContentType { get; set; }
   public ContentTypeDefinition Definition { get; set; }
   public ContentItemBuilder Builder { get; set; }}
At this point any class can be part of the creation process and add it's own logic to inject parts. The default logic comes from ContentPartDriverCoordinator, whose Activating() implementation is just about looking at all the defined parts for this type, match it with all available content part Drivers, and weld a new instance of the part if there is a driver for it.
This actually doesn't mean that a driver is mandatory, because in the case of dynamic content types there is no concrete class for the content type. In this case a generic ContentPart instance will be used, and there won't be any record associated with this part.



作者原创内容不容易,如果觉得内容不错,请点击右侧“打赏”,赏俩给作者花花,也算是对作者付出的肯定,也可以鼓励作者原创更多更好内容。
更多详情欢迎到QQ群 166852192 交流。