Class PartialViewService
Provides services for managing partial view files in Umbraco.
Inheritance
Namespace: Umbraco.Cms.Core.Services
Assembly: Umbraco.Core.dll
Syntax
public class PartialViewService : FileServiceOperationBase<IPartialViewRepository, IPartialView, PartialViewOperationStatus>, IService, IPartialViewService, IBasicFileService<IPartialView>
Remarks
This service handles CRUD operations for partial view files (.cshtml) stored in the file system, including creating, updating, renaming, and deleting partial views. It also provides access to partial view snippets that can be used as templates when creating new partial views.
Constructors
View SourcePartialViewService(ICoreScopeProvider, ILoggerFactory, IEventMessagesFactory, IPartialViewRepository, ILogger<StylesheetService>, IUserIdKeyResolver, IAuditRepository, PartialViewSnippetCollection)
Declaration
[Obsolete("Use the non-obsolete constructor instead. Scheduled for removal in Umbraco 18.")]
public PartialViewService(ICoreScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IPartialViewRepository repository, ILogger<StylesheetService> logger, IUserIdKeyResolver userIdKeyResolver, IAuditRepository auditRepository, PartialViewSnippetCollection snippetCollection)
Parameters
| Type | Name | Description |
|---|---|---|
| ICoreScopeProvider | provider | |
| ILoggerFactory | loggerFactory | |
| IEventMessagesFactory | eventMessagesFactory | |
| IPartialViewRepository | repository | |
| ILogger<StylesheetService> | logger | |
| IUserIdKeyResolver | userIdKeyResolver | |
| IAuditRepository | auditRepository | |
| PartialViewSnippetCollection | snippetCollection |
PartialViewService(ICoreScopeProvider, ILoggerFactory, IEventMessagesFactory, IPartialViewRepository, ILogger<StylesheetService>, IUserIdKeyResolver, IAuditService, IAuditRepository, PartialViewSnippetCollection)
Declaration
[Obsolete("Use the non-obsolete constructor instead. Scheduled for removal in Umbraco 18.")]
public PartialViewService(ICoreScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IPartialViewRepository repository, ILogger<StylesheetService> logger, IUserIdKeyResolver userIdKeyResolver, IAuditService auditService, IAuditRepository auditRepository, PartialViewSnippetCollection snippetCollection)
Parameters
| Type | Name | Description |
|---|---|---|
| ICoreScopeProvider | provider | |
| ILoggerFactory | loggerFactory | |
| IEventMessagesFactory | eventMessagesFactory | |
| IPartialViewRepository | repository | |
| ILogger<StylesheetService> | logger | |
| IUserIdKeyResolver | userIdKeyResolver | |
| IAuditService | auditService | |
| IAuditRepository | auditRepository | |
| PartialViewSnippetCollection | snippetCollection |
PartialViewService(ICoreScopeProvider, ILoggerFactory, IEventMessagesFactory, IPartialViewRepository, ILogger<StylesheetService>, IUserIdKeyResolver, IAuditService, PartialViewSnippetCollection)
Declaration
[Obsolete("Use the non-obsolete constructor instead. Scheduled for removal in Umbraco 18.")]
public PartialViewService(ICoreScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IPartialViewRepository repository, ILogger<StylesheetService> logger, IUserIdKeyResolver userIdKeyResolver, IAuditService auditService, PartialViewSnippetCollection snippetCollection)
Parameters
| Type | Name | Description |
|---|---|---|
| ICoreScopeProvider | provider | |
| ILoggerFactory | loggerFactory | |
| IEventMessagesFactory | eventMessagesFactory | |
| IPartialViewRepository | repository | |
| ILogger<StylesheetService> | logger | |
| IUserIdKeyResolver | userIdKeyResolver | |
| IAuditService | auditService | |
| PartialViewSnippetCollection | snippetCollection |
PartialViewService(ICoreScopeProvider, ILoggerFactory, IEventMessagesFactory, IPartialViewRepository, ILogger<StylesheetService>, IUserIdKeyResolver, IAuditService, PartialViewSnippetCollection, IOptions<RuntimeSettings>)
Initializes a new instance of the PartialViewService class.
Declaration
[ActivatorUtilitiesConstructor]
public PartialViewService(ICoreScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, IPartialViewRepository repository, ILogger<StylesheetService> logger, IUserIdKeyResolver userIdKeyResolver, IAuditService auditService, PartialViewSnippetCollection snippetCollection, IOptions<RuntimeSettings> runtimeSettings)
Parameters
| Type | Name | Description |
|---|---|---|
| ICoreScopeProvider | provider | The core scope provider for managing database transactions. |
| ILoggerFactory | loggerFactory | The factory for creating loggers. |
| IEventMessagesFactory | eventMessagesFactory | The factory for creating event messages. |
| IPartialViewRepository | repository | The repository for partial view file operations. |
| ILogger<StylesheetService> | logger | The logger instance for logging operations. |
| IUserIdKeyResolver | userIdKeyResolver | The resolver for converting user keys to IDs. |
| IAuditService | auditService | The service for audit logging. |
| PartialViewSnippetCollection | snippetCollection | The collection of available partial view snippets. |
| IOptions<RuntimeSettings> | runtimeSettings | The runtime configuration settings. |
Properties
View SourceAllowedFileExtensions
Gets the allowed file extensions for this file type.
Declaration
protected override string[] AllowedFileExtensions { get; }
Property Value
| Type | Description |
|---|---|
| string[] |
AlreadyExists
Gets the operation status value representing an entity that already exists.
Declaration
protected override PartialViewOperationStatus AlreadyExists { get; }
Property Value
| Type | Description |
|---|---|
| PartialViewOperationStatus |
CancelledByNotification
Gets the operation status value representing a cancellation by notification handler.
Declaration
protected override PartialViewOperationStatus CancelledByNotification { get; }
Property Value
| Type | Description |
|---|---|
| PartialViewOperationStatus |
EntityType
Gets the entity type name used for audit logging.
Declaration
protected override string EntityType { get; }
Property Value
| Type | Description |
|---|---|
| string |
InvalidFileExtension
Gets the operation status value representing an invalid file extension.
Declaration
protected override PartialViewOperationStatus InvalidFileExtension { get; }
Property Value
| Type | Description |
|---|---|
| PartialViewOperationStatus |
InvalidName
Gets the operation status value representing an invalid file name.
Declaration
protected override PartialViewOperationStatus InvalidName { get; }
Property Value
| Type | Description |
|---|---|
| PartialViewOperationStatus |
NotFound
Gets the operation status value representing an entity not found condition.
Declaration
protected override PartialViewOperationStatus NotFound { get; }
Property Value
| Type | Description |
|---|---|
| PartialViewOperationStatus |
ParentNotFound
Gets the operation status value representing a parent folder not found condition.
Declaration
protected override PartialViewOperationStatus ParentNotFound { get; }
Property Value
| Type | Description |
|---|---|
| PartialViewOperationStatus |
PathTooLong
Gets the operation status value representing a path that exceeds maximum length.
Declaration
protected override PartialViewOperationStatus PathTooLong { get; }
Property Value
| Type | Description |
|---|---|
| PartialViewOperationStatus |
Success
Gets the operation status value representing a successful operation.
Declaration
protected override PartialViewOperationStatus Success { get; }
Property Value
| Type | Description |
|---|---|
| PartialViewOperationStatus |
Methods
View SourceCreateAsync(PartialViewCreateModel, Guid)
Creates a new partial view.
Declaration
public Task<Attempt<IPartialView?, PartialViewOperationStatus>> CreateAsync(PartialViewCreateModel createModel, Guid userKey)
Parameters
| Type | Name | Description |
|---|---|---|
| PartialViewCreateModel | createModel | PartialViewCreateModel containing the information about the partial view being created. |
| Guid | userKey | The key of the user performing the operation. |
Returns
| Type | Description |
|---|---|
| Task<Attempt<IPartialView, PartialViewOperationStatus>> | An attempt indicating if the operation was a success as well as a more detailed PartialViewOperationStatus. |
CreateEntity(string, string?)
Creates a new entity instance with the specified path and content.
Declaration
protected override IPartialView CreateEntity(string path, string? content)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The file path for the entity. |
| string | content | The optional content of the file. |
Returns
| Type | Description |
|---|---|
| IPartialView | A new entity instance. |
DeleteAsync(string, Guid)
Deletes a partial view.
Declaration
public Task<PartialViewOperationStatus> DeleteAsync(string path, Guid userKey)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The path of the partial view to delete. |
| Guid | userKey | The key of the user performing the operation. |
Returns
| Type | Description |
|---|---|
| Task<PartialViewOperationStatus> | An operation status. |
DeletedNotification(IPartialView, EventMessages)
Creates a deleted notification for the specified entity.
Declaration
protected override PartialViewDeletedNotification DeletedNotification(IPartialView target, EventMessages messages)
Parameters
| Type | Name | Description |
|---|---|---|
| IPartialView | target | The entity that was deleted. |
| EventMessages | messages | The event messages to include. |
Returns
| Type | Description |
|---|---|
| PartialViewDeletedNotification | A deleted notification instance. |
DeletingNotification(IPartialView, EventMessages)
Creates a deleting notification for the specified entity.
Declaration
protected override PartialViewDeletingNotification DeletingNotification(IPartialView target, EventMessages messages)
Parameters
| Type | Name | Description |
|---|---|---|
| IPartialView | target | The entity being deleted. |
| EventMessages | messages | The event messages to include. |
Returns
| Type | Description |
|---|---|
| PartialViewDeletingNotification | A deleting notification instance. |
GetSnippetAsync(string)
Gets a partial view snippet by ID, returns null if not found.
Declaration
public Task<PartialViewSnippet?> GetSnippetAsync(string id)
Parameters
| Type | Name | Description |
|---|---|---|
| string | id | The name of the snippet to get. |
Returns
| Type | Description |
|---|---|
| Task<PartialViewSnippet> | The partial view snippet, null if not found. |
GetSnippetsAsync(int, int)
Gets all the available partial view snippets.
Declaration
public Task<PagedModel<PartialViewSnippetSlim>> GetSnippetsAsync(int skip, int take)
Parameters
| Type | Name | Description |
|---|---|---|
| int | skip | Amount to skip. |
| int | take | Amount to take. |
Returns
| Type | Description |
|---|---|
| Task<PagedModel<PartialViewSnippetSlim>> |
RenameAsync(string, PartialViewRenameModel, Guid)
Renames a partial view.
Declaration
public Task<Attempt<IPartialView?, PartialViewOperationStatus>> RenameAsync(string path, PartialViewRenameModel renameModel, Guid userKey)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The path of the partial view to rename. |
| PartialViewRenameModel | renameModel | A PartialViewRenameModel with the changes. |
| Guid | userKey | The key of the user performing the operation. |
Returns
| Type | Description |
|---|---|
| Task<Attempt<IPartialView, PartialViewOperationStatus>> | An attempt indicating if the operation was a success as well as a more detailed PartialViewOperationStatus. |
SavedNotification(IPartialView, EventMessages)
Creates a saved notification for the specified entity.
Declaration
protected override PartialViewSavedNotification SavedNotification(IPartialView target, EventMessages messages)
Parameters
| Type | Name | Description |
|---|---|---|
| IPartialView | target | The entity that was saved. |
| EventMessages | messages | The event messages to include. |
Returns
| Type | Description |
|---|---|
| PartialViewSavedNotification | A saved notification instance. |
SavingNotification(IPartialView, EventMessages)
Creates a saving notification for the specified entity.
Declaration
protected override PartialViewSavingNotification SavingNotification(IPartialView target, EventMessages messages)
Parameters
| Type | Name | Description |
|---|---|---|
| IPartialView | target | The entity being saved. |
| EventMessages | messages | The event messages to include. |
Returns
| Type | Description |
|---|---|
| PartialViewSavingNotification | A saving notification instance. |
UpdateAsync(string, PartialViewUpdateModel, Guid)
Updates an existing partial view.
Declaration
public Task<Attempt<IPartialView?, PartialViewOperationStatus>> UpdateAsync(string path, PartialViewUpdateModel updateModel, Guid userKey)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The path of the partial view to update. |
| PartialViewUpdateModel | updateModel | A PartialViewUpdateModel with the changes. |
| Guid | userKey | The key of the user performing the operation. |
Returns
| Type | Description |
|---|---|
| Task<Attempt<IPartialView, PartialViewOperationStatus>> | An attempt indicating if the operation was a success as well as a more detailed PartialViewOperationStatus. |