问题
The documentation for content handlers in Orchard mentions Lifecycle Events
(http://docs.orchardproject.net/Documentation/Understanding-content-handlers).
Most events are self explanatory, but I was wondering if anybody can tell me the differences between OnActivated
, OnInitializing
, and OnLoading
?
回答1:
In firing order:
OnActivated
- content item object hierarchy has been created, but not yet fetched from dbUsed for preparing content part for further usage. Eg. setting getters and setters for lazy loaded objects, setting up delegates etc. Think of it as of a "constructor" for a given part.
OnInitializing
- content item object hierarchy has been created, but not yet fetched from db.Used for setting initial/default property values for a given part.
OnLoading
- content item is about to be loaded from db.Used for various things. Fired only if an item exists in the database and is about to be loaded. Orchard core uses this event to set up lazy loaders for part records.
OnLoaded
- content item has been loaded from dbUsed for various things. Fired only if an item exists in the database and all record loaders have been set. You can be sure that
part.Record
will not be null for any part at this point and will contain data fetched from database.
来源:https://stackoverflow.com/questions/16441705/what-are-the-definitions-of-each-of-the-lifecycle-events-in-orchards-cms