Merge pull request #10661 from vsilvar/v9/feature/10648-umbracobuilder-extensions-chaining
Updated public IUmbracoBuilder extension methods to allow chaining
This commit is contained in:
@@ -11,9 +11,10 @@ namespace Umbraco.Extensions
|
||||
/// </summary>
|
||||
/// <param name="builder">The builder.</param>
|
||||
/// <param name="factory">A function creating a published snapshot service.</param>
|
||||
public static void SetPublishedSnapshotService(this IUmbracoBuilder builder, Func<IServiceProvider, IPublishedSnapshotService> factory)
|
||||
public static IUmbracoBuilder SetPublishedSnapshotService(this IUmbracoBuilder builder, Func<IServiceProvider, IPublishedSnapshotService> factory)
|
||||
{
|
||||
builder.Services.AddUnique(factory);
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -21,10 +22,11 @@ namespace Umbraco.Extensions
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the published snapshot service.</typeparam>
|
||||
/// <param name="builder">The builder.</param>
|
||||
public static void SetPublishedSnapshotService<T>(this IUmbracoBuilder builder)
|
||||
public static IUmbracoBuilder SetPublishedSnapshotService<T>(this IUmbracoBuilder builder)
|
||||
where T : class, IPublishedSnapshotService
|
||||
{
|
||||
builder.Services.AddUnique<IPublishedSnapshotService, T>();
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -32,9 +34,10 @@ namespace Umbraco.Extensions
|
||||
/// </summary>
|
||||
/// <param name="builder">The builder.</param>
|
||||
/// <param name="service">A published snapshot service.</param>
|
||||
public static void SetPublishedSnapshotService(this IUmbracoBuilder builder, IPublishedSnapshotService service)
|
||||
public static IUmbracoBuilder SetPublishedSnapshotService(this IUmbracoBuilder builder, IPublishedSnapshotService service)
|
||||
{
|
||||
builder.Services.AddUnique(service);
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,8 @@ using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Umbraco.Cms.Core.Cache;
|
||||
using Umbraco.Cms.Core.DependencyInjection;
|
||||
using Umbraco.Cms.Core.Events;
|
||||
using Umbraco.Cms.Core.Notifications;
|
||||
using Umbraco.Cms.Core.PublishedCache;
|
||||
using Umbraco.Cms.Core.Services.Changes;
|
||||
using Umbraco.Cms.Core.Sync;
|
||||
using Umbraco.Cms.Infrastructure.Search;
|
||||
using Umbraco.Cms.Infrastructure.Sync;
|
||||
using Umbraco.Extensions;
|
||||
|
||||
@@ -40,49 +36,67 @@ namespace Umbraco.Cms.Infrastructure.DependencyInjection
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the server registrar.</typeparam>
|
||||
/// <param name="builder">The builder.</param>
|
||||
public static void SetServerRegistrar<T>(this IUmbracoBuilder builder)
|
||||
public static IUmbracoBuilder SetServerRegistrar<T>(this IUmbracoBuilder builder)
|
||||
where T : class, IServerRoleAccessor
|
||||
=> builder.Services.AddUnique<IServerRoleAccessor, T>();
|
||||
{
|
||||
builder.Services.AddUnique<IServerRoleAccessor, T>();
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the server registrar.
|
||||
/// </summary>
|
||||
/// <param name="builder">The builder.</param>
|
||||
/// <param name="factory">A function creating a server registrar.</param>
|
||||
public static void SetServerRegistrar(this IUmbracoBuilder builder, Func<IServiceProvider, IServerRoleAccessor> factory)
|
||||
=> builder.Services.AddUnique(factory);
|
||||
public static IUmbracoBuilder SetServerRegistrar(this IUmbracoBuilder builder, Func<IServiceProvider, IServerRoleAccessor> factory)
|
||||
{
|
||||
builder.Services.AddUnique(factory);
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the server registrar.
|
||||
/// </summary>
|
||||
/// <param name="builder">The builder.</param>
|
||||
/// <param name="registrar">A server registrar.</param>
|
||||
public static void SetServerRegistrar(this IUmbracoBuilder builder, IServerRoleAccessor registrar)
|
||||
=> builder.Services.AddUnique(registrar);
|
||||
public static IUmbracoBuilder SetServerRegistrar(this IUmbracoBuilder builder, IServerRoleAccessor registrar)
|
||||
{
|
||||
builder.Services.AddUnique(registrar);
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the server messenger.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the server registrar.</typeparam>
|
||||
/// <param name="builder">The builder.</param>
|
||||
public static void SetServerMessenger<T>(this IUmbracoBuilder builder)
|
||||
public static IUmbracoBuilder SetServerMessenger<T>(this IUmbracoBuilder builder)
|
||||
where T : class, IServerMessenger
|
||||
=> builder.Services.AddUnique<IServerMessenger, T>();
|
||||
{
|
||||
builder.Services.AddUnique<IServerMessenger, T>();
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the server messenger.
|
||||
/// </summary>
|
||||
/// <param name="builder">The builder.</param>
|
||||
/// <param name="factory">A function creating a server messenger.</param>
|
||||
public static void SetServerMessenger(this IUmbracoBuilder builder, Func<IServiceProvider, IServerMessenger> factory)
|
||||
=> builder.Services.AddUnique(factory);
|
||||
public static IUmbracoBuilder SetServerMessenger(this IUmbracoBuilder builder, Func<IServiceProvider, IServerMessenger> factory)
|
||||
{
|
||||
builder.Services.AddUnique(factory);
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the server messenger.
|
||||
/// </summary>
|
||||
/// <param name="builder">The builder.</param>
|
||||
/// <param name="registrar">A server messenger.</param>
|
||||
public static void SetServerMessenger(this IUmbracoBuilder builder, IServerMessenger registrar)
|
||||
=> builder.Services.AddUnique(registrar);
|
||||
public static IUmbracoBuilder SetServerMessenger(this IUmbracoBuilder builder, IServerMessenger registrar)
|
||||
{
|
||||
builder.Services.AddUnique(registrar);
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Umbraco.Cms.Core.DependencyInjection;
|
||||
using Umbraco.Cms.Core.Dictionary;
|
||||
using Umbraco.Cms.Core.IO;
|
||||
@@ -21,10 +20,11 @@ namespace Umbraco.Cms.Infrastructure.DependencyInjection
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the factory.</typeparam>
|
||||
/// <param name="builder">The builder.</param>
|
||||
public static void SetCultureDictionaryFactory<T>(this IUmbracoBuilder builder)
|
||||
public static IUmbracoBuilder SetCultureDictionaryFactory<T>(this IUmbracoBuilder builder)
|
||||
where T : class, ICultureDictionaryFactory
|
||||
{
|
||||
builder.Services.AddUnique<ICultureDictionaryFactory, T>();
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -32,9 +32,10 @@ namespace Umbraco.Cms.Infrastructure.DependencyInjection
|
||||
/// </summary>
|
||||
/// <param name="builder">The builder.</param>
|
||||
/// <param name="factory">A function creating a culture dictionary factory.</param>
|
||||
public static void SetCultureDictionaryFactory(this IUmbracoBuilder builder, Func<IServiceProvider, ICultureDictionaryFactory> factory)
|
||||
public static IUmbracoBuilder SetCultureDictionaryFactory(this IUmbracoBuilder builder, Func<IServiceProvider, ICultureDictionaryFactory> factory)
|
||||
{
|
||||
builder.Services.AddUnique(factory);
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -42,9 +43,10 @@ namespace Umbraco.Cms.Infrastructure.DependencyInjection
|
||||
/// </summary>
|
||||
/// <param name="builder">The builder.</param>
|
||||
/// <param name="factory">A factory.</param>
|
||||
public static void SetCultureDictionaryFactory(this IUmbracoBuilder builder, ICultureDictionaryFactory factory)
|
||||
public static IUmbracoBuilder SetCultureDictionaryFactory(this IUmbracoBuilder builder, ICultureDictionaryFactory factory)
|
||||
{
|
||||
builder.Services.AddUnique(factory);
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -52,10 +54,11 @@ namespace Umbraco.Cms.Infrastructure.DependencyInjection
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the factory.</typeparam>
|
||||
/// <param name="builder">The builder.</param>
|
||||
public static void SetPublishedContentModelFactory<T>(this IUmbracoBuilder builder)
|
||||
public static IUmbracoBuilder SetPublishedContentModelFactory<T>(this IUmbracoBuilder builder)
|
||||
where T : class, IPublishedModelFactory
|
||||
{
|
||||
builder.Services.AddUnique<IPublishedModelFactory, T>();
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -63,9 +66,10 @@ namespace Umbraco.Cms.Infrastructure.DependencyInjection
|
||||
/// </summary>
|
||||
/// <param name="builder">The builder.</param>
|
||||
/// <param name="factory">A function creating a published content model factory.</param>
|
||||
public static void SetPublishedContentModelFactory(this IUmbracoBuilder builder, Func<IServiceProvider, IPublishedModelFactory> factory)
|
||||
public static IUmbracoBuilder SetPublishedContentModelFactory(this IUmbracoBuilder builder, Func<IServiceProvider, IPublishedModelFactory> factory)
|
||||
{
|
||||
builder.Services.AddUnique(factory);
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -73,9 +77,10 @@ namespace Umbraco.Cms.Infrastructure.DependencyInjection
|
||||
/// </summary>
|
||||
/// <param name="builder">The builder.</param>
|
||||
/// <param name="factory">A published content model factory.</param>
|
||||
public static void SetPublishedContentModelFactory(this IUmbracoBuilder builder, IPublishedModelFactory factory)
|
||||
public static IUmbracoBuilder SetPublishedContentModelFactory(this IUmbracoBuilder builder, IPublishedModelFactory factory)
|
||||
{
|
||||
builder.Services.AddUnique(factory);
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -83,10 +88,11 @@ namespace Umbraco.Cms.Infrastructure.DependencyInjection
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the short string helper.</typeparam>
|
||||
/// <param name="builder">The builder.</param>
|
||||
public static void SetShortStringHelper<T>(this IUmbracoBuilder builder)
|
||||
public static IUmbracoBuilder SetShortStringHelper<T>(this IUmbracoBuilder builder)
|
||||
where T : class, IShortStringHelper
|
||||
{
|
||||
builder.Services.AddUnique<IShortStringHelper, T>();
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -94,9 +100,10 @@ namespace Umbraco.Cms.Infrastructure.DependencyInjection
|
||||
/// </summary>
|
||||
/// <param name="builder">The builder.</param>
|
||||
/// <param name="factory">A function creating a short string helper.</param>
|
||||
public static void SetShortStringHelper(this IUmbracoBuilder builder, Func<IServiceProvider, IShortStringHelper> factory)
|
||||
public static IUmbracoBuilder SetShortStringHelper(this IUmbracoBuilder builder, Func<IServiceProvider, IShortStringHelper> factory)
|
||||
{
|
||||
builder.Services.AddUnique(factory);
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -104,9 +111,10 @@ namespace Umbraco.Cms.Infrastructure.DependencyInjection
|
||||
/// </summary>
|
||||
/// <param name="builder">A builder.</param>
|
||||
/// <param name="helper">A short string helper.</param>
|
||||
public static void SetShortStringHelper(this IUmbracoBuilder builder, IShortStringHelper helper)
|
||||
public static IUmbracoBuilder SetShortStringHelper(this IUmbracoBuilder builder, IShortStringHelper helper)
|
||||
{
|
||||
builder.Services.AddUnique(helper);
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -114,19 +122,23 @@ namespace Umbraco.Cms.Infrastructure.DependencyInjection
|
||||
/// </summary>
|
||||
/// <param name="builder">A builder.</param>
|
||||
/// <param name="filesystemFactory">Factory method to create an IFileSystem implementation used in the MediaFileManager</param>
|
||||
public static void SetMediaFileSystem(this IUmbracoBuilder builder,
|
||||
Func<IServiceProvider, IFileSystem> filesystemFactory) => builder.Services.AddUnique(
|
||||
provider =>
|
||||
{
|
||||
IFileSystem filesystem = filesystemFactory(provider);
|
||||
// We need to use the Filesystems to create a shadow wrapper,
|
||||
// because shadow wrapper requires the IsScoped delegate from the FileSystems.
|
||||
// This is used by the scope provider when taking control of the filesystems.
|
||||
FileSystems fileSystems = provider.GetRequiredService<FileSystems>();
|
||||
IFileSystem shadow = fileSystems.CreateShadowWrapper(filesystem, "media");
|
||||
public static IUmbracoBuilder SetMediaFileSystem(this IUmbracoBuilder builder,
|
||||
Func<IServiceProvider, IFileSystem> filesystemFactory)
|
||||
{
|
||||
builder.Services.AddUnique(
|
||||
provider =>
|
||||
{
|
||||
IFileSystem filesystem = filesystemFactory(provider);
|
||||
// We need to use the Filesystems to create a shadow wrapper,
|
||||
// because shadow wrapper requires the IsScoped delegate from the FileSystems.
|
||||
// This is used by the scope provider when taking control of the filesystems.
|
||||
FileSystems fileSystems = provider.GetRequiredService<FileSystems>();
|
||||
IFileSystem shadow = fileSystems.CreateShadowWrapper(filesystem, "media");
|
||||
|
||||
return provider.CreateInstance<MediaFileManager>(shadow);
|
||||
});
|
||||
return provider.CreateInstance<MediaFileManager>(shadow);
|
||||
});
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Register FileSystems with a method to configure the <see cref="FileSystems"/>.
|
||||
@@ -135,7 +147,7 @@ namespace Umbraco.Cms.Infrastructure.DependencyInjection
|
||||
/// <param name="configure">Method that configures the <see cref="FileSystems"/>.</param>
|
||||
/// <exception cref="ArgumentNullException">Throws exception if <paramref name="configure"/> is null.</exception>
|
||||
/// <exception cref="InvalidOperationException">Throws exception if full path can't be resolved successfully.</exception>
|
||||
public static void ConfigureFileSystems(this IUmbracoBuilder builder,
|
||||
public static IUmbracoBuilder ConfigureFileSystems(this IUmbracoBuilder builder,
|
||||
Action<IServiceProvider, FileSystems> configure)
|
||||
{
|
||||
if (configure == null)
|
||||
@@ -150,6 +162,7 @@ namespace Umbraco.Cms.Infrastructure.DependencyInjection
|
||||
configure(provider, fileSystems);
|
||||
return fileSystems;
|
||||
});
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -157,10 +170,11 @@ namespace Umbraco.Cms.Infrastructure.DependencyInjection
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the log viewer.</typeparam>
|
||||
/// <param name="builder">The builder.</param>
|
||||
public static void SetLogViewer<T>(this IUmbracoBuilder builder)
|
||||
public static IUmbracoBuilder SetLogViewer<T>(this IUmbracoBuilder builder)
|
||||
where T : class, ILogViewer
|
||||
{
|
||||
builder.Services.AddUnique<ILogViewer, T>();
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -168,19 +182,21 @@ namespace Umbraco.Cms.Infrastructure.DependencyInjection
|
||||
/// </summary>
|
||||
/// <param name="builder">The builder.</param>
|
||||
/// <param name="factory">A function creating a log viewer.</param>
|
||||
public static void SetLogViewer(this IUmbracoBuilder builder, Func<IServiceProvider, ILogViewer> factory)
|
||||
public static IUmbracoBuilder SetLogViewer(this IUmbracoBuilder builder, Func<IServiceProvider, ILogViewer> factory)
|
||||
{
|
||||
builder.Services.AddUnique(factory);
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the log viewer.
|
||||
/// </summary>
|
||||
/// <param name="builder">A builder.</param>
|
||||
/// <param name="helper">A log viewer.</param>
|
||||
public static void SetLogViewer(this IUmbracoBuilder builder, ILogViewer viewer)
|
||||
/// <param name="viewer">A log viewer.</param>
|
||||
public static IUmbracoBuilder SetLogViewer(this IUmbracoBuilder builder, ILogViewer viewer)
|
||||
{
|
||||
builder.Services.AddUnique(viewer);
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,10 +16,11 @@ namespace Umbraco.Extensions
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the content last chance finder.</typeparam>
|
||||
/// <param name="builder">The builder.</param>
|
||||
public static void SetContentLastChanceFinder<T>(this IUmbracoBuilder builder)
|
||||
public static IUmbracoBuilder SetContentLastChanceFinder<T>(this IUmbracoBuilder builder)
|
||||
where T : class, IContentLastChanceFinder
|
||||
{
|
||||
builder.Services.AddUnique<IContentLastChanceFinder, T>();
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -27,9 +28,10 @@ namespace Umbraco.Extensions
|
||||
/// </summary>
|
||||
/// <param name="builder">The builder.</param>
|
||||
/// <param name="factory">A function creating a last chance finder.</param>
|
||||
public static void SetContentLastChanceFinder(this IUmbracoBuilder builder, Func<IServiceProvider, IContentLastChanceFinder> factory)
|
||||
public static IUmbracoBuilder SetContentLastChanceFinder(this IUmbracoBuilder builder, Func<IServiceProvider, IContentLastChanceFinder> factory)
|
||||
{
|
||||
builder.Services.AddUnique(factory);
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -37,9 +39,10 @@ namespace Umbraco.Extensions
|
||||
/// </summary>
|
||||
/// <param name="builder">The builder.</param>
|
||||
/// <param name="finder">A last chance finder.</param>
|
||||
public static void SetContentLastChanceFinder(this IUmbracoBuilder builder, IContentLastChanceFinder finder)
|
||||
public static IUmbracoBuilder SetContentLastChanceFinder(this IUmbracoBuilder builder, IContentLastChanceFinder finder)
|
||||
{
|
||||
builder.Services.AddUnique(finder);
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -47,10 +50,11 @@ namespace Umbraco.Extensions
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the site domain helper.</typeparam>
|
||||
/// <param name="builder"></param>
|
||||
public static void SetSiteDomainHelper<T>(this IUmbracoBuilder builder)
|
||||
public static IUmbracoBuilder SetSiteDomainHelper<T>(this IUmbracoBuilder builder)
|
||||
where T : class, ISiteDomainMapper
|
||||
{
|
||||
builder.Services.AddUnique<ISiteDomainMapper, T>();
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -58,9 +62,10 @@ namespace Umbraco.Extensions
|
||||
/// </summary>
|
||||
/// <param name="builder">The builder.</param>
|
||||
/// <param name="factory">A function creating a helper.</param>
|
||||
public static void SetSiteDomainHelper(this IUmbracoBuilder builder, Func<IServiceProvider, ISiteDomainMapper> factory)
|
||||
public static IUmbracoBuilder SetSiteDomainHelper(this IUmbracoBuilder builder, Func<IServiceProvider, ISiteDomainMapper> factory)
|
||||
{
|
||||
builder.Services.AddUnique(factory);
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -68,9 +73,10 @@ namespace Umbraco.Extensions
|
||||
/// </summary>
|
||||
/// <param name="builder">The builder.</param>
|
||||
/// <param name="helper">A helper.</param>
|
||||
public static void SetSiteDomainHelper(this IUmbracoBuilder builder, ISiteDomainMapper helper)
|
||||
public static IUmbracoBuilder SetSiteDomainHelper(this IUmbracoBuilder builder, ISiteDomainMapper helper)
|
||||
{
|
||||
builder.Services.AddUnique(helper);
|
||||
return builder;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user