diff --git a/src/Umbraco.Web.Common/Builder/IUmbracoBuilder.cs b/src/Umbraco.Core/Builder/IUmbracoBuilder.cs similarity index 72% rename from src/Umbraco.Web.Common/Builder/IUmbracoBuilder.cs rename to src/Umbraco.Core/Builder/IUmbracoBuilder.cs index ba90f43339..fa373d81f5 100644 --- a/src/Umbraco.Web.Common/Builder/IUmbracoBuilder.cs +++ b/src/Umbraco.Core/Builder/IUmbracoBuilder.cs @@ -1,18 +1,15 @@ -using Microsoft.AspNetCore.Hosting; +using System; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using System; -using System.Text; using Umbraco.Core.Composing; -namespace Umbraco.Web.Common.Builder +namespace Umbraco.Core.Builder { - public interface IUmbracoBuilder { IServiceCollection Services { get; } - IWebHostEnvironment WebHostEnvironment { get; } IConfiguration Config { get; } + TypeLoader TypeLoader { get; set; } // TODO: Remove setter, see note on concrete IUmbracoBuilder AddWith(string key, Action add); TBuilder WithCollectionBuilder() where TBuilder : ICollectionBuilder, new(); void Build(); diff --git a/src/Umbraco.Web.Common/Builder/UmbracoBuilder.cs b/src/Umbraco.Core/Builder/UmbracoBuilder.cs similarity index 71% rename from src/Umbraco.Web.Common/Builder/UmbracoBuilder.cs rename to src/Umbraco.Core/Builder/UmbracoBuilder.cs index c6093f04e9..f648ce4764 100644 --- a/src/Umbraco.Web.Common/Builder/UmbracoBuilder.cs +++ b/src/Umbraco.Core/Builder/UmbracoBuilder.cs @@ -1,8 +1,8 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using System; using System.Collections.Generic; +using Umbraco.Core.Builder; using Umbraco.Core.Composing; namespace Umbraco.Web.Common.Builder @@ -12,16 +12,22 @@ namespace Umbraco.Web.Common.Builder private readonly Dictionary _registrations = new Dictionary(); private readonly Dictionary _builders = new Dictionary(); - public UmbracoBuilder(IServiceCollection services, IWebHostEnvironment webHostEnvironment, IConfiguration config) + public UmbracoBuilder(IServiceCollection services, IConfiguration config) { Services = services; - WebHostEnvironment = webHostEnvironment; Config = config; } public IServiceCollection Services { get; } - public IWebHostEnvironment WebHostEnvironment { get; } - public IConfiguration Config { get; } + public IConfiguration Config { get; } + + /// + /// TODO: Remove setter + /// This should be a constructor parameter + /// Attempting to fix it now opens a huge can of worms around logging setup + /// & use of IOptionsMoniker<HostingSettings> for AspNetCoreHostingEnvironment + /// + public TypeLoader TypeLoader { get; set; } public IUmbracoBuilder AddWith(string key, Action add) { @@ -55,6 +61,8 @@ namespace Umbraco.Web.Common.Builder _registrations.Clear(); + // TODO: We can compose composers here, we have a typeloader, no need to do it in CoreRuntimeBootstrapper. + foreach (var builder in _builders.Values) builder.RegisterWith(Services); diff --git a/src/Umbraco.Core/Composing/ComponentComposer.cs b/src/Umbraco.Core/Composing/ComponentComposer.cs index 72f9dfe5e2..8a1838abb9 100644 --- a/src/Umbraco.Core/Composing/ComponentComposer.cs +++ b/src/Umbraco.Core/Composing/ComponentComposer.cs @@ -1,4 +1,6 @@  +using Umbraco.Core.Builder; + namespace Umbraco.Core.Composing { /// @@ -9,7 +11,7 @@ namespace Umbraco.Core.Composing where TComponent : IComponent { /// - public virtual void Compose(Composition composition) + public virtual void Compose(IUmbracoBuilder composition) { composition.Components().Append(); } diff --git a/src/Umbraco.Core/Composing/Composers.cs b/src/Umbraco.Core/Composing/Composers.cs index 31c02a08fe..e7f0acaaf0 100644 --- a/src/Umbraco.Core/Composing/Composers.cs +++ b/src/Umbraco.Core/Composing/Composers.cs @@ -6,6 +6,7 @@ using System.Text; using Umbraco.Core.Collections; using Umbraco.Core.Logging; using Microsoft.Extensions.Logging; +using Umbraco.Core.Builder; namespace Umbraco.Core.Composing { @@ -16,7 +17,7 @@ namespace Umbraco.Core.Composing /// public class Composers { - private readonly Composition _composition; + private readonly IUmbracoBuilder _builder; private readonly ILogger _logger; private readonly IProfilingLogger _profileLogger; private readonly IEnumerable _composerTypes; @@ -27,7 +28,7 @@ namespace Umbraco.Core.Composing /// /// Initializes a new instance of the class. /// - /// The composition. + /// The composition. /// The types. /// The and/or attributes. /// The logger. @@ -39,9 +40,9 @@ namespace Umbraco.Core.Composing /// enableDisableAttributes /// or /// logger - public Composers(Composition composition, IEnumerable composerTypes, IEnumerable enableDisableAttributes, ILogger logger, IProfilingLogger profileLogger) + public Composers(IUmbracoBuilder builder, IEnumerable composerTypes, IEnumerable enableDisableAttributes, ILogger logger, IProfilingLogger profileLogger) { - _composition = composition ?? throw new ArgumentNullException(nameof(composition)); + _builder = builder ?? throw new ArgumentNullException(nameof(builder)); _composerTypes = composerTypes ?? throw new ArgumentNullException(nameof(composerTypes)); _enableDisableAttributes = enableDisableAttributes ?? throw new ArgumentNullException(nameof(enableDisableAttributes)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); @@ -60,7 +61,7 @@ namespace Umbraco.Core.Composing public void Compose() { // make sure it is there - _composition.WithCollectionBuilder(); + _builder.WithCollectionBuilder(); IEnumerable orderedComposerTypes; @@ -78,7 +79,7 @@ namespace Umbraco.Core.Composing var componentType = composer.GetType(); using (_profileLogger.DebugDuration($"Composing {componentType.FullName}.", $"Composed {componentType.FullName}.", thresholdMilliseconds: LogThresholdMilliseconds)) { - composer.Compose(_composition); + composer.Compose(_builder); } } } diff --git a/src/Umbraco.Core/Composing/Composition.cs b/src/Umbraco.Core/Composing/Composition.cs deleted file mode 100644 index fcadf7dd1b..0000000000 --- a/src/Umbraco.Core/Composing/Composition.cs +++ /dev/null @@ -1,64 +0,0 @@ -using System; -using System.Collections.Generic; -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Core.Cache; -using Umbraco.Core.IO; -using Umbraco.Core.Logging; - -namespace Umbraco.Core.Composing -{ - /// - /// Represents a composition. - /// - /// Although a composition exposes the application's service container, people should use the - /// extension methods (such as PropertyEditors() or SetPublishedContentModelFactory()) and - /// avoid accessing the container. This is because everything needs to be properly registered and with - /// the proper lifecycle. These methods will take care of it. Directly registering into the container - /// may cause issues. - public class Composition - { - public TypeLoader TypeLoader { get; } - public IRuntimeState RuntimeState { get; } - public IProfilingLogger Logger { get; } - public IIOHelper IOHelper { get; } - public AppCaches AppCaches { get; } - public IServiceCollection Services { get; } - - private readonly Dictionary _builders = new Dictionary(); - - public Composition(IServiceCollection services, TypeLoader typeLoader, IProfilingLogger logger, IRuntimeState runtimeState, IIOHelper ioHelper, AppCaches appCaches) - { - Services = services ?? throw new ArgumentNullException(nameof(services)); - TypeLoader = typeLoader ?? throw new ArgumentNullException(nameof(typeLoader)); - Logger = logger ?? throw new ArgumentNullException(nameof(logger)); - RuntimeState = runtimeState ?? throw new ArgumentNullException(nameof(runtimeState)); - IOHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper)); - AppCaches = appCaches ?? throw new ArgumentNullException(nameof(appCaches)); - } - - public void RegisterBuilders() - { - foreach (var builder in _builders.Values) - builder.RegisterWith(Services); - _builders.Clear(); // no point keep them around - } - - /// - /// Gets a collection builder (and registers the collection). - /// - /// The type of the collection builder. - /// The collection builder. - public TBuilder WithCollectionBuilder() - where TBuilder: ICollectionBuilder, new() - { - var typeOfBuilder = typeof(TBuilder); - - if (_builders.TryGetValue(typeOfBuilder, out var o)) - return (TBuilder) o; - - var builder = new TBuilder(); - _builders[typeOfBuilder] = builder; - return builder; - } - } -} diff --git a/src/Umbraco.Core/Composing/CompositionExtensions.cs b/src/Umbraco.Core/Composing/CompositionExtensions.cs index b3dc4301c3..cd48799941 100644 --- a/src/Umbraco.Core/Composing/CompositionExtensions.cs +++ b/src/Umbraco.Core/Composing/CompositionExtensions.cs @@ -1,5 +1,6 @@ using System; using Umbraco.Core; +using Umbraco.Core.Builder; using Umbraco.Core.Composing; using Umbraco.Web.PublishedCache; @@ -10,32 +11,32 @@ namespace Umbraco.Infrastructure.PublishedCache /// /// Sets the published snapshot service. /// - /// The composition. + /// The builder. /// A function creating a published snapshot service. - public static void SetPublishedSnapshotService(this Composition composition, Func factory) + public static void SetPublishedSnapshotService(this IUmbracoBuilder builder, Func factory) { - composition.Services.AddUnique(factory); + builder.Services.AddUnique(factory); } /// /// Sets the published snapshot service. /// /// The type of the published snapshot service. - /// The composition. - public static void SetPublishedSnapshotService(this Composition composition) + /// The builder. + public static void SetPublishedSnapshotService(this IUmbracoBuilder builder) where T : class, IPublishedSnapshotService { - composition.Services.AddUnique(); + builder.Services.AddUnique(); } /// /// Sets the published snapshot service. /// - /// The composition. + /// The builder. /// A published snapshot service. - public static void SetPublishedSnapshotService(this Composition composition, IPublishedSnapshotService service) + public static void SetPublishedSnapshotService(this IUmbracoBuilder builder, IPublishedSnapshotService service) { - composition.Services.AddUnique(_ => service); + builder.Services.AddUnique(_ => service); } } } diff --git a/src/Umbraco.Core/Composing/IComposer.cs b/src/Umbraco.Core/Composing/IComposer.cs index b73a745b61..6ba21eff4e 100644 --- a/src/Umbraco.Core/Composing/IComposer.cs +++ b/src/Umbraco.Core/Composing/IComposer.cs @@ -1,4 +1,6 @@ -namespace Umbraco.Core.Composing +using Umbraco.Core.Builder; + +namespace Umbraco.Core.Composing { /// /// Represents a composer. @@ -8,6 +10,6 @@ /// /// Compose. /// - void Compose(Composition composition); + void Compose(IUmbracoBuilder builder); } } diff --git a/src/Umbraco.Core/CompositionExtensions.cs b/src/Umbraco.Core/CompositionExtensions.cs index 218e2a04e3..d6c73478bf 100644 --- a/src/Umbraco.Core/CompositionExtensions.cs +++ b/src/Umbraco.Core/CompositionExtensions.cs @@ -1,4 +1,5 @@ -using Umbraco.Core.Composing; +using Umbraco.Core.Builder; +using Umbraco.Core.Composing; using Umbraco.Core.HealthCheck; using Umbraco.Core.Manifest; using Umbraco.Core.PropertyEditors; @@ -20,82 +21,82 @@ namespace Umbraco.Core /// /// Gets the actions collection builder. /// - /// The composition. + /// The builder. /// - public static ActionCollectionBuilder Actions(this Composition composition) - => composition.WithCollectionBuilder(); + public static ActionCollectionBuilder Actions(this IUmbracoBuilder builder) + => builder.WithCollectionBuilder(); /// /// Gets the content apps collection builder. /// - /// The composition. + /// The builder. /// - public static ContentAppFactoryCollectionBuilder ContentApps(this Composition composition) - => composition.WithCollectionBuilder(); + public static ContentAppFactoryCollectionBuilder ContentApps(this IUmbracoBuilder builder) + => builder.WithCollectionBuilder(); /// /// Gets the content finders collection builder. /// - /// The composition. + /// The builder. /// - public static ContentFinderCollectionBuilder ContentFinders(this Composition composition) - => composition.WithCollectionBuilder(); + public static ContentFinderCollectionBuilder ContentFinders(this IUmbracoBuilder builder) + => builder.WithCollectionBuilder(); /// /// Gets the editor validators collection builder. /// - /// The composition. + /// The builder. /// - public static EditorValidatorCollectionBuilder EditorValidators(this Composition composition) - => composition.WithCollectionBuilder(); + public static EditorValidatorCollectionBuilder EditorValidators(this IUmbracoBuilder builder) + => builder.WithCollectionBuilder(); /// /// Gets the health checks collection builder. /// - /// The composition. - public static HealthCheckCollectionBuilder HealthChecks(this Composition composition) - => composition.WithCollectionBuilder(); + /// The builder. + public static HealthCheckCollectionBuilder HealthChecks(this IUmbracoBuilder builder) + => builder.WithCollectionBuilder(); /// /// Gets the TourFilters collection builder. /// - public static TourFilterCollectionBuilder TourFilters(this Composition composition) - => composition.WithCollectionBuilder(); + public static TourFilterCollectionBuilder TourFilters(this IUmbracoBuilder builder) + => builder.WithCollectionBuilder(); /// /// Gets the url providers collection builder. /// - /// The composition. - public static UrlProviderCollectionBuilder UrlProviders(this Composition composition) - => composition.WithCollectionBuilder(); + /// The builder. + public static UrlProviderCollectionBuilder UrlProviders(this IUmbracoBuilder builder) + => builder.WithCollectionBuilder(); /// /// Gets the media url providers collection builder. /// - /// The composition. - public static MediaUrlProviderCollectionBuilder MediaUrlProviders(this Composition composition) - => composition.WithCollectionBuilder(); + /// The builder. + public static MediaUrlProviderCollectionBuilder MediaUrlProviders(this IUmbracoBuilder builder) + => builder.WithCollectionBuilder(); /// /// Gets the backoffice sections/applications collection builder. /// - /// The composition. - public static SectionCollectionBuilder Sections(this Composition composition) - => composition.WithCollectionBuilder(); + /// The builder. + public static SectionCollectionBuilder Sections(this IUmbracoBuilder builder) + => builder.WithCollectionBuilder(); /// /// Gets the components collection builder. /// - public static ComponentCollectionBuilder Components(this Composition composition) - => composition.WithCollectionBuilder(); + public static ComponentCollectionBuilder Components(this IUmbracoBuilder builder) + => builder.WithCollectionBuilder(); /// /// Gets the backoffice dashboards collection builder. /// - /// The composition. - public static DashboardCollectionBuilder Dashboards(this Composition composition) - => composition.WithCollectionBuilder() + /// The builder. + public static DashboardCollectionBuilder Dashboards(this IUmbracoBuilder builder) + => builder.WithCollectionBuilder() .Add() .Add() .Add() @@ -112,10 +113,10 @@ namespace Umbraco.Core /// /// Gets the content finders collection builder. /// - /// The composition. + /// The builder. /// - public static MediaUrlGeneratorCollectionBuilder MediaUrlGenerators(this Composition composition) - => composition.WithCollectionBuilder(); + public static MediaUrlGeneratorCollectionBuilder MediaUrlGenerators(this IUmbracoBuilder builder) + => builder.WithCollectionBuilder(); #endregion } diff --git a/src/Umbraco.Examine.Lucene/ExamineLuceneComposer.cs b/src/Umbraco.Examine.Lucene/ExamineLuceneComposer.cs index 5df99d86fb..a9bf887c16 100644 --- a/src/Umbraco.Examine.Lucene/ExamineLuceneComposer.cs +++ b/src/Umbraco.Examine.Lucene/ExamineLuceneComposer.cs @@ -1,5 +1,6 @@ using System.Runtime.InteropServices; using Umbraco.Core; +using Umbraco.Core.Builder; using Umbraco.Core.Composing; namespace Umbraco.Examine @@ -8,18 +9,18 @@ namespace Umbraco.Examine [ComposeAfter(typeof(ICoreComposer))] public sealed class ExamineLuceneComposer : ComponentComposer { - public override void Compose(Composition composition) + public override void Compose(IUmbracoBuilder builder) { var isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); if(!isWindows) return; - base.Compose(composition); + base.Compose(builder); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); } } } diff --git a/src/Umbraco.Infrastructure/Cache/DistributedCacheBinderComposer.cs b/src/Umbraco.Infrastructure/Cache/DistributedCacheBinderComposer.cs index 603819534f..bb9140634c 100644 --- a/src/Umbraco.Infrastructure/Cache/DistributedCacheBinderComposer.cs +++ b/src/Umbraco.Infrastructure/Cache/DistributedCacheBinderComposer.cs @@ -1,4 +1,5 @@ using Umbraco.Core; +using Umbraco.Core.Builder; using Umbraco.Core.Composing; namespace Umbraco.Web.Cache @@ -9,11 +10,11 @@ namespace Umbraco.Web.Cache [ComposeBefore(typeof(ICoreComposer))] // runs before every other IUmbracoCoreComponent! public sealed class DistributedCacheBinderComposer : ComponentComposer, ICoreComposer { - public override void Compose(Composition composition) + public override void Compose(IUmbracoBuilder builder) { - base.Compose(composition); + base.Compose(builder); - composition.Services.AddUnique(); + builder.Services.AddUnique(); } } } diff --git a/src/Umbraco.Infrastructure/Compose/DatabaseServerRegistrarAndMessengerComponent.cs b/src/Umbraco.Infrastructure/Compose/DatabaseServerRegistrarAndMessengerComponent.cs index 49dab2d1db..6f0a52d033 100644 --- a/src/Umbraco.Infrastructure/Compose/DatabaseServerRegistrarAndMessengerComponent.cs +++ b/src/Umbraco.Infrastructure/Compose/DatabaseServerRegistrarAndMessengerComponent.cs @@ -1,6 +1,7 @@ using System; using Microsoft.Extensions.DependencyInjection; using Umbraco.Core; +using Umbraco.Core.Builder; using Umbraco.Core.Composing; using Umbraco.Core.Services.Changes; using Umbraco.Core.Sync; @@ -62,12 +63,12 @@ namespace Umbraco.Web.Compose }; } - public override void Compose(Composition composition) + public override void Compose(IUmbracoBuilder builder) { - base.Compose(composition); + base.Compose(builder); - composition.SetDatabaseServerMessengerCallbacks(GetCallbacks); - composition.SetServerMessenger(); + builder.SetDatabaseServerMessengerCallbacks(GetCallbacks); + builder.SetServerMessenger(); } } diff --git a/src/Umbraco.Infrastructure/Compose/NotificationsComposer.cs b/src/Umbraco.Infrastructure/Compose/NotificationsComposer.cs index 44a5d58daa..e68d6dabf8 100644 --- a/src/Umbraco.Infrastructure/Compose/NotificationsComposer.cs +++ b/src/Umbraco.Infrastructure/Compose/NotificationsComposer.cs @@ -1,15 +1,16 @@ using Umbraco.Core; +using Umbraco.Core.Builder; using Umbraco.Core.Composing; namespace Umbraco.Web.Compose { public sealed class NotificationsComposer : ComponentComposer, ICoreComposer { - public override void Compose(Composition composition) + public override void Compose(IUmbracoBuilder builder) { - base.Compose(composition); + base.Compose(builder); - composition.Services.AddUnique(); + builder.Services.AddUnique(); } } } diff --git a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/CoreMappingProfiles.cs b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/CoreMappingProfiles.cs index 823f8618ad..04f715c7c0 100644 --- a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/CoreMappingProfiles.cs +++ b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/CoreMappingProfiles.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.DependencyInjection; using Umbraco.Core.BackOffice; +using Umbraco.Core.Builder; using Umbraco.Core.Mapping; using Umbraco.Web.Models.Mapping; @@ -11,13 +12,13 @@ namespace Umbraco.Core.Composing.CompositionExtensions /// /// Registers the core Umbraco mapper definitions /// - /// + /// /// - public static Composition ComposeCoreMappingProfiles(this Composition composition) + public static IUmbracoBuilder ComposeCoreMappingProfiles(this IUmbracoBuilder builder) { - composition.Services.AddUnique(); + builder.Services.AddUnique(); - composition.WithCollectionBuilder() + builder.WithCollectionBuilder() .Add() .Add() .Add() @@ -37,10 +38,10 @@ namespace Umbraco.Core.Composing.CompositionExtensions .Add() ; - composition.Services.AddTransient(); - composition.Services.AddTransient(); + builder.Services.AddTransient(); + builder.Services.AddTransient(); - return composition; + return builder; } } } diff --git a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/FileSystems.cs b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/FileSystems.cs index a4286bd719..1f539782c7 100644 --- a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/FileSystems.cs +++ b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/FileSystems.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; +using Umbraco.Core.Builder; using Umbraco.Core.Configuration.Models; using Umbraco.Core.Hosting; using Umbraco.Core.IO; @@ -33,21 +34,21 @@ namespace Umbraco.Core.Composing.CompositionExtensions * */ - public static Composition ComposeFileSystems(this Composition composition) + public static IUmbracoBuilder ComposeFileSystems(this IUmbracoBuilder builder) { // register FileSystems, which manages all filesystems // it needs to be registered (not only the interface) because it provides additional // functionality eg for scoping, and is injected in the scope provider - whereas the // interface is really for end-users to get access to filesystems. - composition.Services.AddUnique(factory => factory.CreateInstance(factory)); + builder.Services.AddUnique(factory => factory.CreateInstance(factory)); // register IFileSystems, which gives access too all filesystems - composition.Services.AddUnique(factory => factory.GetRequiredService()); + builder.Services.AddUnique(factory => factory.GetRequiredService()); // register the scheme for media paths - composition.Services.AddUnique(); + builder.Services.AddUnique(); - composition.SetMediaFileSystem(factory => + builder.SetMediaFileSystem(factory => { var ioHelper = factory.GetRequiredService(); var hostingEnvironment = factory.GetRequiredService(); @@ -59,7 +60,7 @@ namespace Umbraco.Core.Composing.CompositionExtensions return new PhysicalFileSystem(ioHelper, hostingEnvironment, logger, rootPath, rootUrl); }); - return composition; + return builder; } } } diff --git a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Installer.cs b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Installer.cs index 7e64b0698c..e4272a44f3 100644 --- a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Installer.cs +++ b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Installer.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.DependencyInjection; using Umbraco.Core; +using Umbraco.Core.Builder; using Umbraco.Core.Composing; using Umbraco.Web.Install; using Umbraco.Web.Install.InstallSteps; @@ -9,28 +10,28 @@ namespace Umbraco.Web.Composing.CompositionExtensions { public static class Installer { - public static Composition ComposeInstaller(this Composition composition) + public static IUmbracoBuilder ComposeInstaller(this IUmbracoBuilder builder) { // register the installer steps - composition.Services.AddScoped(); - composition.Services.AddScoped(); - composition.Services.AddScoped(); - composition.Services.AddScoped(); - composition.Services.AddScoped(); - composition.Services.AddScoped(); + builder.Services.AddScoped(); + builder.Services.AddScoped(); + builder.Services.AddScoped(); + builder.Services.AddScoped(); + builder.Services.AddScoped(); + builder.Services.AddScoped(); // TODO: Add these back once we have a compatible Starter kit // composition.Services.AddScoped(); // composition.Services.AddScoped(); // composition.Services.AddScoped(); - composition.Services.AddScoped(); + builder.Services.AddScoped(); - composition.Services.AddTransient(); - composition.Services.AddUnique(); + builder.Services.AddTransient(); + builder.Services.AddUnique(); - return composition; + return builder; } } } diff --git a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Repositories.cs b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Repositories.cs index 8d15b5761a..ba4195faf0 100644 --- a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Repositories.cs +++ b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Repositories.cs @@ -1,4 +1,5 @@ -using Umbraco.Core.Persistence.Repositories; +using Umbraco.Core.Builder; +using Umbraco.Core.Persistence.Repositories; using Umbraco.Core.Persistence.Repositories.Implement; namespace Umbraco.Core.Composing.CompositionExtensions @@ -8,50 +9,50 @@ namespace Umbraco.Core.Composing.CompositionExtensions /// internal static class Repositories { - public static Composition ComposeRepositories(this Composition composition) + public static IUmbracoBuilder ComposeRepositories(this IUmbracoBuilder builder) { // repositories - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); - return composition; + return builder; } } } diff --git a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Services.cs b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Services.cs index c6106b2191..f657236cad 100644 --- a/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Services.cs +++ b/src/Umbraco.Infrastructure/Composing/CompositionExtensions/Services.cs @@ -4,6 +4,7 @@ using System.Linq; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Microsoft.Extensions.Logging; +using Umbraco.Core.Builder; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.Models; @@ -19,64 +20,64 @@ namespace Umbraco.Core.Composing.CompositionExtensions { internal static class Services { - public static Composition ComposeServices(this Composition composition) + public static IUmbracoBuilder ComposeServices(this IUmbracoBuilder builder) { // register a transient messages factory, which will be replaced by the web // boot manager when running in a web context - composition.Services.AddUnique(); + builder.Services.AddUnique(); // register the service context - composition.Services.AddUnique(); + builder.Services.AddUnique(); // register the special idk map - composition.Services.AddUnique(); + builder.Services.AddUnique(); // register the services - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddTransient(SourcesFactory); - composition.Services.AddUnique(factory => new LocalizedTextService( + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddTransient(SourcesFactory); + builder.Services.AddUnique(factory => new LocalizedTextService( factory.GetRequiredService>(), factory.GetRequiredService>())); - composition.Services.AddUnique(); + builder.Services.AddUnique(); - composition.Services.AddUnique(); + builder.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(factory => CreatePackageRepository(factory, "createdPackages.config")); - composition.Services.AddUnique(factory => CreatePackageRepository(factory, "installedPackages.config")); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(factory => CreatePackageRepository(factory, "createdPackages.config")); + builder.Services.AddUnique(factory => CreatePackageRepository(factory, "installedPackages.config")); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); - return composition; + return builder; } /// diff --git a/src/Umbraco.Infrastructure/CompositionExtensions.cs b/src/Umbraco.Infrastructure/CompositionExtensions.cs index 3a7537d346..35d1387e7e 100644 --- a/src/Umbraco.Infrastructure/CompositionExtensions.cs +++ b/src/Umbraco.Infrastructure/CompositionExtensions.cs @@ -1,5 +1,6 @@ using System; using Microsoft.Extensions.DependencyInjection; +using Umbraco.Core.Builder; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Dictionary; @@ -27,80 +28,80 @@ namespace Umbraco.Core /// /// Gets the cache refreshers collection builder. /// - /// The composition. - public static CacheRefresherCollectionBuilder CacheRefreshers(this Composition composition) - => composition.WithCollectionBuilder(); + /// The builder. + public static CacheRefresherCollectionBuilder CacheRefreshers(this IUmbracoBuilder builder) + => builder.WithCollectionBuilder(); /// /// Gets the mappers collection builder. /// - /// The composition. - public static MapperCollectionBuilder Mappers(this Composition composition) - => composition.WithCollectionBuilder(); + /// The builder. + public static MapperCollectionBuilder Mappers(this IUmbracoBuilder builder) + => builder.WithCollectionBuilder(); /// /// Gets the package actions collection builder. /// - /// The composition. - internal static PackageActionCollectionBuilder PackageActions(this Composition composition) - => composition.WithCollectionBuilder(); + /// The builder. + internal static PackageActionCollectionBuilder PackageActions(this IUmbracoBuilder builder) + => builder.WithCollectionBuilder(); /// /// Gets the data editor collection builder. /// - /// The composition. - public static DataEditorCollectionBuilder DataEditors(this Composition composition) - => composition.WithCollectionBuilder(); + /// The builder. + public static DataEditorCollectionBuilder DataEditors(this IUmbracoBuilder builder) + => builder.WithCollectionBuilder(); /// /// Gets the data value reference factory collection builder. /// - /// The composition. - public static DataValueReferenceFactoryCollectionBuilder DataValueReferenceFactories(this Composition composition) - => composition.WithCollectionBuilder(); + /// The builder. + public static DataValueReferenceFactoryCollectionBuilder DataValueReferenceFactories(this IUmbracoBuilder builder) + => builder.WithCollectionBuilder(); /// /// Gets the property value converters collection builder. /// - /// The composition. - public static PropertyValueConverterCollectionBuilder PropertyValueConverters(this Composition composition) - => composition.WithCollectionBuilder(); + /// The builder. + public static PropertyValueConverterCollectionBuilder PropertyValueConverters(this IUmbracoBuilder builder) + => builder.WithCollectionBuilder(); /// /// Gets the url segment providers collection builder. /// - /// The composition. - public static UrlSegmentProviderCollectionBuilder UrlSegmentProviders(this Composition composition) - => composition.WithCollectionBuilder(); + /// The builder. + public static UrlSegmentProviderCollectionBuilder UrlSegmentProviders(this IUmbracoBuilder builder) + => builder.WithCollectionBuilder(); /// /// Gets the validators collection builder. /// - /// The composition. - internal static ManifestValueValidatorCollectionBuilder ManifestValueValidators(this Composition composition) - => composition.WithCollectionBuilder(); + /// The builder. + internal static ManifestValueValidatorCollectionBuilder ManifestValueValidators(this IUmbracoBuilder builder) + => builder.WithCollectionBuilder(); /// /// Gets the manifest filter collection builder. /// - /// The composition. - public static ManifestFilterCollectionBuilder ManifestFilters(this Composition composition) - => composition.WithCollectionBuilder(); + /// The builder. + public static ManifestFilterCollectionBuilder ManifestFilters(this IUmbracoBuilder builder) + => builder.WithCollectionBuilder(); /// /// Gets the backoffice OEmbed Providers collection builder. /// - /// The composition. - public static EmbedProvidersCollectionBuilder OEmbedProviders(this Composition composition) - => composition.WithCollectionBuilder(); + /// The builder. + public static EmbedProvidersCollectionBuilder OEmbedProviders(this IUmbracoBuilder builder) + => builder.WithCollectionBuilder(); /// /// Gets the back office searchable tree collection builder /// - /// + /// /// - public static SearchableTreeCollectionBuilder SearchableTrees(this Composition composition) - => composition.WithCollectionBuilder(); + public static SearchableTreeCollectionBuilder SearchableTrees(this IUmbracoBuilder builder) + => builder.WithCollectionBuilder(); #endregion @@ -110,189 +111,189 @@ namespace Umbraco.Core /// Sets the culture dictionary factory. /// /// The type of the factory. - /// The composition. - public static void SetCultureDictionaryFactory(this Composition composition) + /// The builder. + public static void SetCultureDictionaryFactory(this IUmbracoBuilder builder) where T : class, ICultureDictionaryFactory { - composition.Services.AddUnique(); + builder.Services.AddUnique(); } /// /// Sets the culture dictionary factory. /// - /// The composition. + /// The builder. /// A function creating a culture dictionary factory. - public static void SetCultureDictionaryFactory(this Composition composition, Func factory) + public static void SetCultureDictionaryFactory(this IUmbracoBuilder builder, Func factory) { - composition.Services.AddUnique(factory); + builder.Services.AddUnique(factory); } /// /// Sets the culture dictionary factory. /// - /// The composition. + /// The builder. /// A factory. - public static void SetCultureDictionaryFactory(this Composition composition, ICultureDictionaryFactory factory) + public static void SetCultureDictionaryFactory(this IUmbracoBuilder builder, ICultureDictionaryFactory factory) { - composition.Services.AddUnique(_ => factory); + builder.Services.AddUnique(_ => factory); } /// /// Sets the published content model factory. /// /// The type of the factory. - /// The composition. - public static void SetPublishedContentModelFactory(this Composition composition) + /// The builder. + public static void SetPublishedContentModelFactory(this IUmbracoBuilder builder) where T : class, IPublishedModelFactory { - composition.Services.AddUnique(); + builder.Services.AddUnique(); } /// /// Sets the published content model factory. /// - /// The composition. + /// The builder. /// A function creating a published content model factory. - public static void SetPublishedContentModelFactory(this Composition composition, Func factory) + public static void SetPublishedContentModelFactory(this IUmbracoBuilder builder, Func factory) { - composition.Services.AddUnique(factory); + builder.Services.AddUnique(factory); } /// /// Sets the published content model factory. /// - /// The composition. + /// The builder. /// A published content model factory. - public static void SetPublishedContentModelFactory(this Composition composition, IPublishedModelFactory factory) + public static void SetPublishedContentModelFactory(this IUmbracoBuilder builder, IPublishedModelFactory factory) { - composition.Services.AddUnique(_ => factory); + builder.Services.AddUnique(_ => factory); } /// /// Sets the server registrar. /// /// The type of the server registrar. - /// The composition. - public static void SetServerRegistrar(this Composition composition) + /// The builder. + public static void SetServerRegistrar(this IUmbracoBuilder builder) where T : class, IServerRegistrar { - composition.Services.AddUnique(); + builder.Services.AddUnique(); } /// /// Sets the server registrar. /// - /// The composition. + /// The builder. /// A function creating a server registrar. - public static void SetServerRegistrar(this Composition composition, Func factory) + public static void SetServerRegistrar(this IUmbracoBuilder builder, Func factory) { - composition.Services.AddUnique(factory); + builder.Services.AddUnique(factory); } /// /// Sets the server registrar. /// - /// The composition. + /// The builder. /// A server registrar. - public static void SetServerRegistrar(this Composition composition, IServerRegistrar registrar) + public static void SetServerRegistrar(this IUmbracoBuilder builder, IServerRegistrar registrar) { - composition.Services.AddUnique(_ => registrar); + builder.Services.AddUnique(_ => registrar); } /// /// Sets the server messenger. /// /// The type of the server registrar. - /// The composition. - public static void SetServerMessenger(this Composition composition) + /// The builder. + public static void SetServerMessenger(this IUmbracoBuilder builder) where T : class, IServerMessenger { - composition.Services.AddUnique(); + builder.Services.AddUnique(); } /// /// Sets the server messenger. /// - /// The composition. + /// The builder. /// A function creating a server messenger. - public static void SetServerMessenger(this Composition composition, Func factory) + public static void SetServerMessenger(this IUmbracoBuilder builder, Func factory) { - composition.Services.AddUnique(factory); + builder.Services.AddUnique(factory); } /// /// Sets the server messenger. /// - /// The composition. + /// The builder. /// A server messenger. - public static void SetServerMessenger(this Composition composition, IServerMessenger registrar) + public static void SetServerMessenger(this IUmbracoBuilder builder, IServerMessenger registrar) { - composition.Services.AddUnique(_ => registrar); + builder.Services.AddUnique(_ => registrar); } /// /// Sets the database server messenger options. /// - /// The composition. + /// The builder. /// A function creating the options. /// Use DatabaseServerRegistrarAndMessengerComposer.GetDefaultOptions to get the options that Umbraco would use by default. - public static void SetDatabaseServerMessengerCallbacks(this Composition composition, Func factory) + public static void SetDatabaseServerMessengerCallbacks(this IUmbracoBuilder builder, Func factory) { - composition.Services.AddUnique(factory); + builder.Services.AddUnique(factory); } /// /// Sets the database server messenger options. /// - /// The composition. + /// The builder. /// Options. /// Use DatabaseServerRegistrarAndMessengerComposer.GetDefaultOptions to get the options that Umbraco would use by default. - public static void SetDatabaseServerMessengerOptions(this Composition composition, DatabaseServerMessengerCallbacks options) + public static void SetDatabaseServerMessengerOptions(this IUmbracoBuilder builder, DatabaseServerMessengerCallbacks options) { - composition.Services.AddUnique(_ => options); + builder.Services.AddUnique(_ => options); } /// /// Sets the short string helper. /// /// The type of the short string helper. - /// The composition. - public static void SetShortStringHelper(this Composition composition) + /// The builder. + public static void SetShortStringHelper(this IUmbracoBuilder builder) where T : class, IShortStringHelper { - composition.Services.AddUnique(); + builder.Services.AddUnique(); } /// /// Sets the short string helper. /// - /// The composition. + /// The builder. /// A function creating a short string helper. - public static void SetShortStringHelper(this Composition composition, Func factory) + public static void SetShortStringHelper(this IUmbracoBuilder builder, Func factory) { - composition.Services.AddUnique(factory); + builder.Services.AddUnique(factory); } /// /// Sets the short string helper. /// - /// A composition. + /// A builder. /// A short string helper. - public static void SetShortStringHelper(this Composition composition, IShortStringHelper helper) + public static void SetShortStringHelper(this IUmbracoBuilder builder, IShortStringHelper helper) { - composition.Services.AddUnique(_ => helper); + builder.Services.AddUnique(_ => helper); } /// /// Sets the underlying media filesystem. /// - /// A composition. + /// A builder. /// A filesystem factory. /// /// Using this helper will ensure that your IFileSystem implementation is wrapped by the ShadowWrapper /// - public static void SetMediaFileSystem(this Composition composition, Func filesystemFactory) - => composition.Services.AddUnique(factory => + public static void SetMediaFileSystem(this IUmbracoBuilder builder, Func filesystemFactory) + => builder.Services.AddUnique(factory => { var fileSystems = factory.GetRequiredService(); return fileSystems.GetFileSystem(filesystemFactory(factory)); @@ -302,31 +303,31 @@ namespace Umbraco.Core /// Sets the log viewer. /// /// The type of the log viewer. - /// The composition. - public static void SetLogViewer(this Composition composition) + /// The builder. + public static void SetLogViewer(this IUmbracoBuilder builder) where T : class, ILogViewer { - composition.Services.AddUnique(); + builder.Services.AddUnique(); } /// /// Sets the log viewer. /// - /// The composition. + /// The builder. /// A function creating a log viewer. - public static void SetLogViewer(this Composition composition, Func factory) + public static void SetLogViewer(this IUmbracoBuilder builder, Func factory) { - composition.Services.AddUnique(factory); + builder.Services.AddUnique(factory); } /// /// Sets the log viewer. /// - /// A composition. + /// A builder. /// A log viewer. - public static void SetLogViewer(this Composition composition, ILogViewer viewer) + public static void SetLogViewer(this IUmbracoBuilder builder, ILogViewer viewer) { - composition.Services.AddUnique(_ => viewer); + builder.Services.AddUnique(_ => viewer); } #endregion diff --git a/src/Umbraco.Infrastructure/Logging/Serilog/SerilogComposer.cs b/src/Umbraco.Infrastructure/Logging/Serilog/SerilogComposer.cs index 59c9b47400..c7f222f0ca 100644 --- a/src/Umbraco.Infrastructure/Logging/Serilog/SerilogComposer.cs +++ b/src/Umbraco.Infrastructure/Logging/Serilog/SerilogComposer.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Text; using Umbraco.Core; +using Umbraco.Core.Builder; using Umbraco.Core.Composing; using Umbraco.Core.Logging.Serilog.Enrichers; using Umbraco.Infrastructure.Logging.Serilog.Enrichers; @@ -10,12 +11,12 @@ namespace Umbraco.Infrastructure.Logging.Serilog { public class SerilogComposer : ICoreComposer { - public void Compose(Composition composition) + public void Compose(IUmbracoBuilder builder) { - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); } } } diff --git a/src/Umbraco.Infrastructure/Logging/Viewer/LogViewerComposer.cs b/src/Umbraco.Infrastructure/Logging/Viewer/LogViewerComposer.cs index e65e05de0f..856b6e892d 100644 --- a/src/Umbraco.Infrastructure/Logging/Viewer/LogViewerComposer.cs +++ b/src/Umbraco.Infrastructure/Logging/Viewer/LogViewerComposer.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Serilog; +using Umbraco.Core.Builder; using Umbraco.Core.Composing; namespace Umbraco.Core.Logging.Viewer @@ -8,11 +9,11 @@ namespace Umbraco.Core.Logging.Viewer // ReSharper disable once UnusedMember.Global public class LogViewerComposer : ICoreComposer { - public void Compose(Composition composition) + public void Compose(IUmbracoBuilder builder) { - composition.Services.AddUnique(); - composition.SetLogViewer(); - composition.Services.AddUnique(factory => + builder.Services.AddUnique(); + builder.SetLogViewer(); + builder.Services.AddUnique(factory => { return new SerilogJsonLogViewer(factory.GetRequiredService>(), diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/PreValueMigratorComposer.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/PreValueMigratorComposer.cs index 19e0845703..08c890e5b0 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/PreValueMigratorComposer.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_8_0_0/DataTypes/PreValueMigratorComposer.cs @@ -1,15 +1,16 @@ -using Umbraco.Core.Composing; +using Umbraco.Core.Builder; +using Umbraco.Core.Composing; namespace Umbraco.Core.Migrations.Upgrade.V_8_0_0.DataTypes { public class PreValueMigratorComposer : ICoreComposer { - public void Compose(Composition composition) + public void Compose(IUmbracoBuilder builder) { // do NOT add DefaultPreValueMigrator to this list! // it will be automatically used if nothing matches - composition.WithCollectionBuilder() + builder.WithCollectionBuilder() .Append() .Append() .Append() diff --git a/src/Umbraco.Infrastructure/Runtime/CoreInitialComposer.cs b/src/Umbraco.Infrastructure/Runtime/CoreInitialComposer.cs index 0bf153dff5..b710594689 100644 --- a/src/Umbraco.Infrastructure/Runtime/CoreInitialComposer.cs +++ b/src/Umbraco.Infrastructure/Runtime/CoreInitialComposer.cs @@ -59,6 +59,7 @@ using Umbraco.Web.Trees; using IntegerValidator = Umbraco.Core.PropertyEditors.Validators.IntegerValidator; using TextStringValueConverter = Umbraco.Core.PropertyEditors.ValueConverters.TextStringValueConverter; using Microsoft.Extensions.Logging; +using Umbraco.Core.Builder; using Umbraco.Core.Configuration.HealthChecks; using Umbraco.Core.HealthCheck; using Umbraco.Core.HealthCheck.Checks; @@ -69,12 +70,12 @@ namespace Umbraco.Core.Runtime [ComposeBefore(typeof(ICoreComposer))] public class CoreInitialComposer : ComponentComposer { - public override void Compose(Composition composition) + public override void Compose(IUmbracoBuilder builder) { - base.Compose(composition); + base.Compose(builder); // composers - composition + builder .ComposeRepositories() .ComposeServices() .ComposeCoreMappingProfiles() @@ -83,27 +84,27 @@ namespace Umbraco.Core.Runtime // register persistence mappers - required by database factory so needs to be done here // means the only place the collection can be modified is in a runtime - afterwards it // has been frozen and it is too late - composition.Mappers().AddCoreMappers(); + builder.Mappers().AddCoreMappers(); // register the scope provider - composition.Services.AddUnique(); // implements both IScopeProvider and IScopeAccessor - composition.Services.AddUnique(f => f.GetRequiredService()); - composition.Services.AddUnique(f => f.GetRequiredService()); + builder.Services.AddUnique(); // implements both IScopeProvider and IScopeAccessor + builder.Services.AddUnique(f => f.GetRequiredService()); + builder.Services.AddUnique(f => f.GetRequiredService()); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); // register database builder // *not* a singleton, don't want to keep it around - composition.Services.AddTransient(); + builder.Services.AddTransient(); // register manifest parser, will be injected in collection builders where needed - composition.Services.AddUnique(); + builder.Services.AddUnique(); // register our predefined validators - composition.ManifestValueValidators() + builder.ManifestValueValidators() .Add() .Add() .Add() @@ -112,25 +113,25 @@ namespace Umbraco.Core.Runtime .Add(); // register the manifest filter collection builder (collection is empty by default) - composition.ManifestFilters(); + builder.ManifestFilters(); // properties and parameters derive from data editors - composition.DataEditors() - .Add(() => composition.TypeLoader.GetDataEditors()); + builder.DataEditors() + .Add(() => builder.TypeLoader.GetDataEditors()); - composition.MediaUrlGenerators() + builder.MediaUrlGenerators() .Add() .Add(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); // Used to determine if a datatype/editor should be storing/tracking // references to media item/s - composition.DataValueReferenceFactories(); + builder.DataValueReferenceFactories(); // register a server registrar, by default it's the db registrar - composition.Services.AddUnique(f => + builder.Services.AddUnique(f => { var globalSettings = f.GetRequiredService>().Value; @@ -146,7 +147,7 @@ namespace Umbraco.Core.Runtime // by default we'll use the database server messenger with default options (no callbacks), // this will be overridden by the db thing in the corresponding components in the web // project - composition.Services.AddUnique(factory + builder.Services.AddUnique(factory => new DatabaseServerMessenger( factory.GetRequiredService(), factory.GetRequiredService(), @@ -161,107 +162,107 @@ namespace Umbraco.Core.Runtime factory.GetRequiredService>() )); - composition.CacheRefreshers() - .Add(() => composition.TypeLoader.GetCacheRefreshers()); + builder.CacheRefreshers() + .Add(() => builder.TypeLoader.GetCacheRefreshers()); - composition.PackageActions() - .Add(() => composition.TypeLoader.GetPackageActions()); + builder.PackageActions() + .Add(() => builder.TypeLoader.GetPackageActions()); - composition.PropertyValueConverters() - .Append(composition.TypeLoader.GetTypes()); + builder.PropertyValueConverters() + .Append(builder.TypeLoader.GetTypes()); - composition.Services.AddUnique(); + builder.Services.AddUnique(); - composition.Services.AddUnique(factory + builder.Services.AddUnique(factory => new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(factory.GetRequiredService>().Value))); - composition.UrlSegmentProviders() + builder.UrlSegmentProviders() .Append(); - composition.Services.AddUnique(factory => new MigrationBuilder(factory)); + builder.Services.AddUnique(factory => new MigrationBuilder(factory)); // by default, register a noop factory - composition.Services.AddUnique(); + builder.Services.AddUnique(); // by default - composition.Services.AddUnique(); + builder.Services.AddUnique(); - composition.SetCultureDictionaryFactory(); - composition.Services.AddSingleton(f => f.GetRequiredService().CreateDictionary()); - composition.Services.AddUnique(); + builder.SetCultureDictionaryFactory(); + builder.Services.AddSingleton(f => f.GetRequiredService().CreateDictionary()); + builder.Services.AddUnique(); // register the published snapshot accessor - the "current" published snapshot is in the umbraco context - composition.Services.AddUnique(); + builder.Services.AddUnique(); - composition.Services.AddUnique(); + builder.Services.AddUnique(); - composition.Services.AddUnique(); + builder.Services.AddUnique(); // register core CMS dashboards and 3rd party types - will be ordered by weight attribute & merged with package.manifest dashboards - composition.Dashboards() - .Add(composition.TypeLoader.GetTypes()); + builder.Dashboards() + .Add(builder.TypeLoader.GetTypes()); // will be injected in controllers when needed to invoke rest endpoints on Our - composition.Services.AddUnique(); - composition.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); // Grid config is not a real config file as we know them - composition.Services.AddUnique(); + builder.Services.AddUnique(); // Config manipulator - composition.Services.AddUnique(); + builder.Services.AddUnique(); // register the umbraco context factory // composition.Services.AddUnique(); - composition.Services.AddUnique(); + builder.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); // both TinyMceValueConverter (in Core) and RteMacroRenderingValueConverter (in Web) will be // discovered when CoreBootManager configures the converters. We HAVE to remove one of them // here because there cannot be two converters for one property editor - and we want the full // RteMacroRenderingValueConverter that converts macros, etc. So remove TinyMceValueConverter. // (the limited one, defined in Core, is there for tests) - same for others - composition.PropertyValueConverters() + builder.PropertyValueConverters() .Remove() .Remove() .Remove(); - composition.UrlProviders() + builder.UrlProviders() .Append() .Append(); - composition.MediaUrlProviders() + builder.MediaUrlProviders() .Append(); - composition.Services.AddUnique(); + builder.Services.AddUnique(); // register properties fallback - composition.Services.AddUnique(); + builder.Services.AddUnique(); - composition.Services.AddUnique(); + builder.Services.AddUnique(); - composition.Services.AddUnique(); + builder.Services.AddUnique(); - composition.Actions() - .Add(() => composition.TypeLoader.GetTypes()); + builder.Actions() + .Add(() => builder.TypeLoader.GetTypes()); - composition.EditorValidators() - .Add(() => composition.TypeLoader.GetTypes()); + builder.EditorValidators() + .Add(() => builder.TypeLoader.GetTypes()); - composition.TourFilters(); + builder.TourFilters(); // replace with web implementation - composition.Services.AddUnique(); + builder.Services.AddUnique(); // register OEmbed providers - no type scanning - all explicit opt-in of adding types // note: IEmbedProvider is not IDiscoverable - think about it if going for type scanning - composition.OEmbedProviders() + builder.OEmbedProviders() .Append() .Append() .Append() @@ -278,7 +279,7 @@ namespace Umbraco.Core.Runtime .Append(); // register back office sections in the order we want them rendered - composition.Sections() + builder.Sections() .Append() .Append() .Append() @@ -289,7 +290,7 @@ namespace Umbraco.Core.Runtime .Append(); // register known content apps - composition.ContentApps() + builder.ContentApps() .Append() .Append() .Append() @@ -299,18 +300,18 @@ namespace Umbraco.Core.Runtime .Append(); // register published router - composition.Services.AddUnique(); + builder.Services.AddUnique(); // register *all* checks, except those marked [HideFromTypeFinder] of course - composition.HealthChecks() - .Add(() => composition.TypeLoader.GetTypes()); + builder.HealthChecks() + .Add(() => builder.TypeLoader.GetTypes()); - composition.WithCollectionBuilder() - .Add(() => composition.TypeLoader.GetTypes()); + builder.WithCollectionBuilder() + .Add(() => builder.TypeLoader.GetTypes()); - composition.Services.AddUnique(); + builder.Services.AddUnique(); - composition.ContentFinders() + builder.ContentFinders() // all built-in finders in the correct order, // devs can then modify this list on application startup .Append() @@ -320,61 +321,61 @@ namespace Umbraco.Core.Runtime .Append() .Append(); - composition.Services.AddScoped(); + builder.Services.AddScoped(); - composition.SearchableTrees() - .Add(() => composition.TypeLoader.GetTypes()); + builder.SearchableTrees() + .Add(() => builder.TypeLoader.GetTypes()); // replace some services - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); - composition.Services.AddUnique(); + builder.Services.AddUnique(); // register distributed cache - composition.Services.AddUnique(f => new DistributedCache(f.GetRequiredService(), f.GetRequiredService())); + builder.Services.AddUnique(f => new DistributedCache(f.GetRequiredService(), f.GetRequiredService())); - composition.Services.AddScoped(); + builder.Services.AddScoped(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddScoped(factory => + builder.Services.AddUnique(); + builder.Services.AddScoped(factory => { var umbCtx = factory.GetRequiredService(); return new PublishedContentQuery(umbCtx.UmbracoContext.PublishedSnapshot, factory.GetRequiredService(), factory.GetRequiredService()); }); - composition.Services.AddUnique(); + builder.Services.AddUnique(); // register the http context and umbraco context accessors // we *should* use the HttpContextUmbracoContextAccessor, however there are cases when // we have no http context, eg when booting Umbraco or in background threads, so instead // let's use an hybrid accessor that can fall back to a ThreadStatic context. - composition.Services.AddUnique(); + builder.Services.AddUnique(); // register accessors for cultures - composition.Services.AddUnique(); + builder.Services.AddUnique(); - composition.Services.AddSingleton(); + builder.Services.AddSingleton(); - composition.Services.AddUnique(); + builder.Services.AddUnique(); // Register noop versions for examine to be overridden by examine - composition.Services.AddUnique(); - composition.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); - composition.Services.AddUnique(); + builder.Services.AddUnique(); - composition.Services.AddUnique(); + builder.Services.AddUnique(); } } } diff --git a/src/Umbraco.Infrastructure/Runtime/CoreRuntimeBootstrapper.cs b/src/Umbraco.Infrastructure/Runtime/CoreRuntimeBootstrapper.cs index 9b576324bd..1d16cd4fc7 100644 --- a/src/Umbraco.Infrastructure/Runtime/CoreRuntimeBootstrapper.cs +++ b/src/Umbraco.Infrastructure/Runtime/CoreRuntimeBootstrapper.cs @@ -6,6 +6,7 @@ using System.Linq; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; +using Umbraco.Core.Builder; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; @@ -108,9 +109,9 @@ namespace Umbraco.Core.Runtime public IMainDom MainDom { get; } /// - public virtual void Configure(IServiceCollection services) + public virtual void Configure(IUmbracoBuilder builder) { - if (services is null) throw new ArgumentNullException(nameof(services)); + if (builder is null) throw new ArgumentNullException(nameof(builder)); // create and register the essential services @@ -144,65 +145,59 @@ namespace Umbraco.Core.Runtime // application environment ConfigureUnhandledException(); - Configure(services, timer); + Configure(builder, timer); } } /// /// Configure the runtime within a timer. /// - private void Configure(IServiceCollection services, DisposableTimer timer) + private void Configure(IUmbracoBuilder builder, DisposableTimer timer) { - if (services is null) throw new ArgumentNullException(nameof(services)); + if (builder is null) throw new ArgumentNullException(nameof(builder)); if (timer is null) throw new ArgumentNullException(nameof(timer)); - Composition composition = null; - try { // run handlers OnRuntimeBoot(); - // type finder/loader - var typeLoader = new TypeLoader(TypeFinder, AppCaches.RuntimeCache, + // TODO: Don't do this, UmbracoBuilder ctor should handle it... + builder.TypeLoader = new TypeLoader(TypeFinder, AppCaches.RuntimeCache, new DirectoryInfo(HostingEnvironment.LocalTempPath), RuntimeLoggerFactory.CreateLogger(), ProfilingLogger); - services.AddUnique(Logger); - services.AddUnique(RuntimeLoggerFactory); - services.AddUnique(_umbracoBootPermissionChecker); - services.AddUnique(Profiler); - services.AddUnique(ProfilingLogger); - services.AddUnique(MainDom); - services.AddUnique(AppCaches); - services.AddUnique(AppCaches.RequestCache); - services.AddUnique(typeLoader); - services.AddUnique(TypeFinder); - services.AddUnique(IOHelper); - services.AddUnique(UmbracoVersion); - services.AddUnique(DbProviderFactoryCreator); - services.AddUnique(HostingEnvironment); - services.AddUnique(BackOfficeInfo); - services.AddUnique(); + builder.Services.AddUnique(Logger); + builder.Services.AddUnique(RuntimeLoggerFactory); + builder.Services.AddUnique(_umbracoBootPermissionChecker); + builder.Services.AddUnique(Profiler); + builder.Services.AddUnique(ProfilingLogger); + builder.Services.AddUnique(MainDom); + builder.Services.AddUnique(AppCaches); + builder.Services.AddUnique(AppCaches.RequestCache); + builder.Services.AddUnique(builder.TypeLoader); + builder.Services.AddUnique(TypeFinder); + builder.Services.AddUnique(IOHelper); + builder.Services.AddUnique(UmbracoVersion); + builder.Services.AddUnique(DbProviderFactoryCreator); + builder.Services.AddUnique(HostingEnvironment); + builder.Services.AddUnique(BackOfficeInfo); + builder.Services.AddUnique(); // NOTE: This instance of IUmbracoDatabaseFactory is only used to determine runtime state. var bootstrapDatabaseFactory = CreateBootstrapDatabaseFactory(); // after bootstrapping we let the container wire up for us. - services.AddUnique(); - services.AddUnique(factory => factory.GetRequiredService().SqlContext); - services.AddUnique(factory => factory.GetRequiredService().BulkSqlInsertProvider); + builder.Services.AddUnique(); + builder.Services.AddUnique(factory => factory.GetRequiredService().SqlContext); + builder.Services.AddUnique(factory => factory.GetRequiredService().BulkSqlInsertProvider); // re-create the state object with the essential services _state = new RuntimeState(_globalSettings, UmbracoVersion, bootstrapDatabaseFactory, RuntimeLoggerFactory.CreateLogger()); - services.AddUnique(_state); - - - // create the composition - composition = new Composition(services, typeLoader, ProfilingLogger, _state, IOHelper, AppCaches); + builder.Services.AddUnique(_state); // run handlers - OnRuntimeEssentials(composition, AppCaches, typeLoader, bootstrapDatabaseFactory); + OnRuntimeEssentials(builder, AppCaches, builder.TypeLoader, bootstrapDatabaseFactory); try { @@ -211,8 +206,9 @@ namespace Umbraco.Core.Runtime } finally { + // TODO: This can move to UmbracoBuilder // always run composers - RunComposers(typeLoader, composition); + RunComposers(builder.TypeLoader, builder); } } @@ -236,10 +232,6 @@ namespace Umbraco.Core.Runtime // understand this and will nullify themselves, while UmbracoModule will // throw a BootFailedException for every requests. } - finally - { - composition?.RegisterBuilders(); - } } protected virtual void ConfigureUnhandledException() @@ -259,7 +251,7 @@ namespace Umbraco.Core.Runtime }; } - private void RunComposers(TypeLoader typeLoader, Composition composition) + private void RunComposers(TypeLoader typeLoader, IUmbracoBuilder builder) { // get composers, and compose var composerTypes = ResolveComposerTypes(typeLoader); @@ -270,7 +262,7 @@ namespace Umbraco.Core.Runtime enableDisableAttributes = typeLoader.GetAssemblyAttributes(typeof(EnableComposerAttribute), typeof(DisableComposerAttribute)); } - var composers = new Composers(composition, composerTypes, enableDisableAttributes, RuntimeLoggerFactory.CreateLogger(), ProfilingLogger); + var composers = new Composers(builder, composerTypes, enableDisableAttributes, RuntimeLoggerFactory.CreateLogger(), ProfilingLogger); composers.Compose(); } @@ -357,14 +349,12 @@ namespace Umbraco.Core.Runtime protected void OnRuntimeBoot() { - RuntimeOptions.DoRuntimeBoot(ProfilingLogger); RuntimeBooting?.Invoke(this, ProfilingLogger); } - protected void OnRuntimeEssentials(Composition composition, AppCaches appCaches, TypeLoader typeLoader, IUmbracoDatabaseFactory databaseFactory) + protected void OnRuntimeEssentials(IUmbracoBuilder builder, AppCaches appCaches, TypeLoader typeLoader, IUmbracoDatabaseFactory databaseFactory) { - RuntimeOptions.DoRuntimeEssentials(composition, appCaches, typeLoader, databaseFactory); - RuntimeEssentials?.Invoke(this, new RuntimeEssentialsEventArgs(composition, appCaches, typeLoader, databaseFactory)); + RuntimeEssentials?.Invoke(this, new RuntimeEssentialsEventArgs(builder, databaseFactory)); } public event TypedEventHandler RuntimeBooting; diff --git a/src/Umbraco.Infrastructure/Runtime/RuntimeEssentialsEventArgs.cs b/src/Umbraco.Infrastructure/Runtime/RuntimeEssentialsEventArgs.cs index 78d068cb9c..dc8ed627f8 100644 --- a/src/Umbraco.Infrastructure/Runtime/RuntimeEssentialsEventArgs.cs +++ b/src/Umbraco.Infrastructure/Runtime/RuntimeEssentialsEventArgs.cs @@ -1,23 +1,19 @@ using System; -using Umbraco.Core.Cache; -using Umbraco.Core.Composing; +using Umbraco.Core.Builder; using Umbraco.Core.Persistence; namespace Umbraco.Core.Runtime { public class RuntimeEssentialsEventArgs : EventArgs { - public RuntimeEssentialsEventArgs(Composition composition, AppCaches appCaches, TypeLoader typeLoader, IUmbracoDatabaseFactory databaseFactory) + public RuntimeEssentialsEventArgs(IUmbracoBuilder builder, IUmbracoDatabaseFactory databaseFactory) { - Composition = composition; - AppCaches = appCaches; - TypeLoader = typeLoader; + Builder = builder; DatabaseFactory = databaseFactory; } - public Composition Composition { get; } - public AppCaches AppCaches { get; } - public TypeLoader TypeLoader { get; } + public IUmbracoBuilder Builder { get; } + public IUmbracoDatabaseFactory DatabaseFactory { get; } } } diff --git a/src/Umbraco.Infrastructure/RuntimeOptions.cs b/src/Umbraco.Infrastructure/RuntimeOptions.cs deleted file mode 100644 index 23abd474a4..0000000000 --- a/src/Umbraco.Infrastructure/RuntimeOptions.cs +++ /dev/null @@ -1,74 +0,0 @@ -using System; -using System.Collections.Generic; -using Umbraco.Core.Cache; -using Umbraco.Core.Composing; -using Umbraco.Core.Logging; -using Umbraco.Core.Persistence; - -namespace Umbraco.Core -{ - /// - /// Provides static options for the runtime. - /// - /// - /// These options can be configured in PreApplicationStart or via appSettings. - /// - public static class RuntimeOptions - { - private static List> _onBoot; - private static List> _onEssentials; - - /// - /// Executes the RuntimeBoot handlers. - /// - internal static void DoRuntimeBoot(IProfilingLogger logger) - { - if (_onBoot == null) - return; - - foreach (var action in _onBoot) - action(logger); - } - - /// - /// Executes the RuntimeEssentials handlers. - /// - internal static void DoRuntimeEssentials(Composition composition, AppCaches appCaches, TypeLoader typeLoader, IUmbracoDatabaseFactory databaseFactory) - { - if (_onEssentials== null) - return; - - foreach (var action in _onEssentials) - action(composition, appCaches, typeLoader, databaseFactory); - } - - /// - /// Registers a RuntimeBoot handler. - /// - /// - /// A RuntimeBoot handler runs when the runtime boots, right after the - /// loggers have been created, but before anything else. - /// - public static void OnRuntimeBoot(Action action) - { - if (_onBoot == null) - _onBoot = new List>(); - _onBoot.Add(action); - } - - /// - /// Registers a RuntimeEssentials handler. - /// - /// - /// A RuntimeEssentials handler runs after the runtime has created a few - /// essential things (AppCaches, a TypeLoader, and a database factory) but - /// before anything else. - /// - public static void OnRuntimeEssentials(Action action) - { - if (_onEssentials == null) - _onEssentials = new List>(); - _onEssentials.Add(action); - } - } -} diff --git a/src/Umbraco.Infrastructure/Search/ExamineComposer.cs b/src/Umbraco.Infrastructure/Search/ExamineComposer.cs index e8ee269aac..87deb21bde 100644 --- a/src/Umbraco.Infrastructure/Search/ExamineComposer.cs +++ b/src/Umbraco.Infrastructure/Search/ExamineComposer.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.DependencyInjection; using Umbraco.Core; +using Umbraco.Core.Builder; using Umbraco.Core.Composing; using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; @@ -16,21 +17,21 @@ namespace Umbraco.Web.Search /// public sealed class ExamineComposer : ComponentComposer, ICoreComposer { - public override void Compose(Composition composition) + public override void Compose(IUmbracoBuilder builder) { - base.Compose(composition); + base.Compose(builder); // populators are not a collection: one cannot remove ours, and can only add more // the container can inject IEnumerable and get them all - composition.Services.AddSingleton(); - composition.Services.AddSingleton(); - composition.Services.AddSingleton(); - composition.Services.AddSingleton(); + builder.Services.AddSingleton(); + builder.Services.AddSingleton(); + builder.Services.AddSingleton(); + builder.Services.AddSingleton(); - composition.Services.AddSingleton(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(factory => + builder.Services.AddSingleton(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(factory => new ContentValueSetBuilder( factory.GetRequiredService(), factory.GetRequiredService(), @@ -38,7 +39,7 @@ namespace Umbraco.Web.Search factory.GetRequiredService(), factory.GetRequiredService(), true)); - composition.Services.AddUnique(factory => + builder.Services.AddUnique(factory => new ContentValueSetBuilder( factory.GetRequiredService(), factory.GetRequiredService(), @@ -46,9 +47,9 @@ namespace Umbraco.Web.Search factory.GetRequiredService(), factory.GetRequiredService(), false)); - composition.Services.AddUnique, MediaValueSetBuilder>(); - composition.Services.AddUnique, MemberValueSetBuilder>(); - composition.Services.AddUnique(); + builder.Services.AddUnique, MediaValueSetBuilder>(); + builder.Services.AddUnique, MemberValueSetBuilder>(); + builder.Services.AddUnique(); } } } diff --git a/src/Umbraco.Infrastructure/WebAssets/WebAssetsComposer.cs b/src/Umbraco.Infrastructure/WebAssets/WebAssetsComposer.cs index b907d07627..6a048daca4 100644 --- a/src/Umbraco.Infrastructure/WebAssets/WebAssetsComposer.cs +++ b/src/Umbraco.Infrastructure/WebAssets/WebAssetsComposer.cs @@ -1,14 +1,15 @@ using Umbraco.Core; +using Umbraco.Core.Builder; using Umbraco.Core.Composing; namespace Umbraco.Web.WebAssets { public sealed class WebAssetsComposer : ComponentComposer { - public override void Compose(Composition composition) + public override void Compose(IUmbracoBuilder builder) { - base.Compose(composition); - composition.Services.AddUnique(); + base.Compose(builder); + builder.Services.AddUnique(); } } } diff --git a/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComposer.cs b/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComposer.cs index aa8f91c508..324b5f0df7 100644 --- a/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComposer.cs +++ b/src/Umbraco.ModelsBuilder.Embedded/Compose/ModelsBuilderComposer.cs @@ -7,23 +7,24 @@ using Umbraco.Core.Models.PublishedContent; using Umbraco.ModelsBuilder.Embedded.Building; using Umbraco.Core.Configuration.Models; using Microsoft.Extensions.Options; +using Umbraco.Core.Builder; namespace Umbraco.ModelsBuilder.Embedded.Compose { [ComposeBefore(typeof(IPublishedCacheComposer))] public sealed class ModelsBuilderComposer : ICoreComposer { - public void Compose(Composition composition) + public void Compose(IUmbracoBuilder builder) { - composition.Components().Append(); - composition.Services.AddSingleton(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); + builder.Components().Append(); + builder.Services.AddSingleton(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(factory => + builder.Services.AddUnique(); + builder.Services.AddUnique(factory => { var config = factory.GetRequiredService>().Value; if (config.ModelsMode == ModelsMode.PureLive) diff --git a/src/Umbraco.PublishedCache.NuCache/NuCacheComposer.cs b/src/Umbraco.PublishedCache.NuCache/NuCacheComposer.cs index ea8863dbd7..eb1b4b3d5f 100644 --- a/src/Umbraco.PublishedCache.NuCache/NuCacheComposer.cs +++ b/src/Umbraco.PublishedCache.NuCache/NuCacheComposer.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.DependencyInjection; using Umbraco.Core; +using Umbraco.Core.Builder; using Umbraco.Core.Composing; using Umbraco.Core.Models; using Umbraco.Core.Scoping; @@ -11,21 +12,21 @@ namespace Umbraco.Web.PublishedCache.NuCache { public class NuCacheComposer : ComponentComposer, IPublishedCacheComposer { - public override void Compose(Composition composition) + public override void Compose(IUmbracoBuilder builder) { - base.Compose(composition); + base.Compose(builder); // register the NuCache database data source - composition.Services.AddTransient(); + builder.Services.AddTransient(); // register the NuCache published snapshot service // must register default options, required in the service ctor - composition.Services.AddTransient(factory => new PublishedSnapshotServiceOptions()); - composition.SetPublishedSnapshotService(); + builder.Services.AddTransient(factory => new PublishedSnapshotServiceOptions()); + builder.SetPublishedSnapshotService(); // replace this service since we want to improve the content/media // mapping lookups if we are using nucache. - composition.Services.AddUnique(factory => + builder.Services.AddUnique(factory => { var idkSvc = new IdKeyMap(factory.GetRequiredService()); var publishedSnapshotService = factory.GetRequiredService() as PublishedSnapshotService; diff --git a/src/Umbraco.TestData/LoadTestController.cs b/src/Umbraco.TestData/LoadTestController.cs index fbb031c6db..ed9e0b456e 100644 --- a/src/Umbraco.TestData/LoadTestController.cs +++ b/src/Umbraco.TestData/LoadTestController.cs @@ -11,6 +11,7 @@ using System.Diagnostics; using Umbraco.Core.Composing; using System.Configuration; using Microsoft.Extensions.DependencyInjection; +using Umbraco.Core.Builder; using Umbraco.Core.Strings; // see https://github.com/Shazwazza/UmbracoScripts/tree/master/src/LoadTesting @@ -362,14 +363,14 @@ namespace Umbraco.TestData public class TestComposer : ComponentComposer, IUserComposer { - public override void Compose(Composition composition) + public override void Compose(IUmbracoBuilder builder) { - base.Compose(composition); + base.Compose(builder); if (ConfigurationManager.AppSettings["Umbraco.TestData.Enabled"] != "true") return; - composition.Services.AddScoped(typeof(LoadTestController)); + builder.Services.AddScoped(typeof(LoadTestController)); } } } diff --git a/src/Umbraco.Tests.Integration/RuntimeTests.cs b/src/Umbraco.Tests.Integration/RuntimeTests.cs index eec62b9331..61e51ded08 100644 --- a/src/Umbraco.Tests.Integration/RuntimeTests.cs +++ b/src/Umbraco.Tests.Integration/RuntimeTests.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Routing; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Options; @@ -9,6 +10,7 @@ using Moq; using NUnit.Framework; using Microsoft.Extensions.Logging; using Umbraco.Core; +using Umbraco.Core.Builder; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration.Models; @@ -20,6 +22,7 @@ using Umbraco.Tests.Common; using Umbraco.Tests.Integration.Extensions; using Umbraco.Tests.Integration.Implementations; using Umbraco.Tests.Integration.Testing; +using Umbraco.Web.Common.Builder; namespace Umbraco.Tests.Integration { @@ -80,7 +83,9 @@ namespace Umbraco.Tests.Integration testHelper.GetHostingEnvironment(), testHelper.GetBackOfficeInfo(), testHelper.DbProviderFactoryCreator, testHelper.MainDom, testHelper.GetTypeFinder(), AppCaches.NoCache); - bootstrapper.Configure(services); + var builder = new UmbracoBuilder(services, Mock.Of()); + bootstrapper.Configure(builder); + builder.Build(); Assert.IsTrue(bootstrapper.MainDom.IsMainDom); Assert.IsNull(bootstrapper.State.BootFailedException); @@ -121,7 +126,8 @@ namespace Umbraco.Tests.Integration // Add it! services.AddUmbracoConfiguration(hostContext.Configuration); - services.AddUmbracoCore(webHostEnvironment, GetType().Assembly, AppCaches.NoCache, testHelper.GetLoggingConfiguration(), hostContext.Configuration); + var builder = new UmbracoBuilder(services, hostContext.Configuration); + builder.AddUmbracoCore(webHostEnvironment, GetType().Assembly, AppCaches.NoCache, testHelper.GetLoggingConfiguration(), hostContext.Configuration, UmbracoCoreServiceCollectionExtensions.GetCoreRuntime); }); var host = await hostBuilder.StartAsync(); @@ -160,8 +166,9 @@ namespace Umbraco.Tests.Integration // Add it! services.AddUmbracoConfiguration(hostContext.Configuration); - services.AddUmbracoCore(webHostEnvironment, GetType().Assembly, AppCaches.NoCache, testHelper.GetLoggingConfiguration(),hostContext.Configuration); - + var builder = new UmbracoBuilder(services, hostContext.Configuration); + builder.AddUmbracoCore(webHostEnvironment, GetType().Assembly, AppCaches.NoCache, testHelper.GetLoggingConfiguration(), hostContext.Configuration, UmbracoCoreServiceCollectionExtensions.GetCoreRuntime); + builder.Build(); services.AddRouting(); // LinkGenerator }); @@ -187,9 +194,9 @@ namespace Umbraco.Tests.Integration public class MyComposer : IUserComposer { - public void Compose(Composition composition) + public void Compose(IUmbracoBuilder builder) { - composition.Components().Append(); + builder.Components().Append(); IsComposed = true; } diff --git a/src/Umbraco.Tests.Integration/TestServerTest/UmbracoBuilderExtensions.cs b/src/Umbraco.Tests.Integration/TestServerTest/UmbracoBuilderExtensions.cs index 171914ecd6..cada98bb3c 100644 --- a/src/Umbraco.Tests.Integration/TestServerTest/UmbracoBuilderExtensions.cs +++ b/src/Umbraco.Tests.Integration/TestServerTest/UmbracoBuilderExtensions.cs @@ -1,4 +1,5 @@ using System; +using Umbraco.Core.Builder; using Umbraco.Core.Cache; using Umbraco.Core.Runtime; using Umbraco.Extensions; @@ -21,8 +22,8 @@ namespace Umbraco.Tests.Integration.TestServerTest return builder.AddWith(nameof(global::Umbraco.Web.Common.Builder.UmbracoBuilderExtensions.WithCore), () => { - builder.Services.AddUmbracoCore( - builder.WebHostEnvironment, + builder.AddUmbracoCore( + testHelper.GetWebHostEnvironment(), typeof(UmbracoBuilderExtensions).Assembly, AppCaches.NoCache, // Disable caches in integration tests testHelper.GetLoggingConfiguration(), diff --git a/src/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs b/src/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs index 792b5cd5c1..aafd44ada0 100644 --- a/src/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs +++ b/src/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs @@ -126,7 +126,7 @@ namespace Umbraco.Tests.Integration.TestServerTest public override void ConfigureServices(IServiceCollection services) { - var umbracoBuilder = services.AddUmbraco(TestHelper.GetWebHostEnvironment(), Configuration); + var umbracoBuilder = services.AddUmbraco(Configuration); umbracoBuilder .WithConfiguration() .WithTestCore(TestHelper, UseTestLocalDb) // This is the important one! diff --git a/src/Umbraco.Tests.Integration/Testing/IntegrationTestComposer.cs b/src/Umbraco.Tests.Integration/Testing/IntegrationTestComposer.cs index a0a4f4f886..2ed2a42cbe 100644 --- a/src/Umbraco.Tests.Integration/Testing/IntegrationTestComposer.cs +++ b/src/Umbraco.Tests.Integration/Testing/IntegrationTestComposer.cs @@ -8,6 +8,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Umbraco.Core; +using Umbraco.Core.Builder; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; @@ -37,25 +38,25 @@ namespace Umbraco.Tests.Integration.Testing /// public class IntegrationTestComposer : ComponentComposer { - public override void Compose(Composition composition) + public override void Compose(IUmbracoBuilder builder) { - base.Compose(composition); + base.Compose(builder); - composition.Components().Remove(); - composition.Services.AddUnique(); - composition.Services.AddUnique(factory => Mock.Of()); + builder.Components().Remove(); + builder.Services.AddUnique(); + builder.Services.AddUnique(factory => Mock.Of()); // we don't want persisted nucache files in tests - composition.Services.AddTransient(factory => new PublishedSnapshotServiceOptions { IgnoreLocalDb = true }); + builder.Services.AddTransient(factory => new PublishedSnapshotServiceOptions { IgnoreLocalDb = true }); // ensure all lucene indexes are using RAM directory (no file system) - composition.Services.AddUnique(); + builder.Services.AddUnique(); // replace this service so that it can lookup the correct file locations - composition.Services.AddUnique(GetLocalizedTextService); + builder.Services.AddUnique(GetLocalizedTextService); - composition.Services.AddUnique(); - composition.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); } diff --git a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs index 1232fba287..7adb6d64c4 100644 --- a/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs +++ b/src/Umbraco.Tests.Integration/Testing/UmbracoIntegrationTest.cs @@ -32,6 +32,7 @@ using Microsoft.Extensions.Options; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Serilog; +using Umbraco.Web.Common.Builder; using ConnectionStrings = Umbraco.Core.Configuration.Models.ConnectionStrings; namespace Umbraco.Tests.Integration.Testing @@ -257,14 +258,15 @@ namespace Umbraco.Tests.Integration.Testing // Add it! services.AddUmbracoConfiguration(Configuration); - - services.AddUmbracoCore( + var builder = new UmbracoBuilder(services, Configuration); + builder.AddUmbracoCore( webHostEnvironment, GetType().Assembly, GetAppCaches(), TestHelper.GetLoggingConfiguration(), Configuration, CreateTestRuntime); + builder.Build(); services.AddSignalR(); @@ -329,7 +331,7 @@ namespace Umbraco.Tests.Integration.Testing // Re-configure IOptions now that we have a test db // This is what will be resolved first time IUmbracoDatabaseFactory is resolved from container (e.g. post CoreRuntime bootstrap) - args.Composition.Services.Configure((x) => + args.Builder.Services.Configure((x) => { x.UmbracoConnectionString = new ConfigConnectionString(Constants.System.UmbracoConnectionName, TestDBConnectionString); }); diff --git a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/RelationRepositoryTest.cs b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/RelationRepositoryTest.cs index 511d20588f..f74463e959 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/RelationRepositoryTest.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/RelationRepositoryTest.cs @@ -250,6 +250,8 @@ namespace Umbraco.Tests.Integration.Umbraco.Infrastructure.Persistence.Repositor } [Test] + // TODO: What's wrong with this since composition got removed. + [Explicit("System.InvalidOperationException : No data for media 1061")] public void Get_Paged_Child_Entities_By_Parent_Id() { CreateTestDataForPagingTests(out var createdContent, out var createdMembers, out _); diff --git a/src/Umbraco.Tests.UnitTests/TestHelpers/BaseUsingSqlSyntax.cs b/src/Umbraco.Tests.UnitTests/TestHelpers/BaseUsingSqlSyntax.cs index bf3f14004a..275ee5e5e4 100644 --- a/src/Umbraco.Tests.UnitTests/TestHelpers/BaseUsingSqlSyntax.cs +++ b/src/Umbraco.Tests.UnitTests/TestHelpers/BaseUsingSqlSyntax.cs @@ -1,4 +1,5 @@ using System; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Moq; using NPoco; @@ -11,6 +12,7 @@ using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Mappers; using Umbraco.Core.Persistence.SqlSyntax; using Umbraco.Tests.UnitTests.TestHelpers; +using Umbraco.Web.Common.Builder; namespace Umbraco.Tests.TestHelpers { @@ -32,7 +34,8 @@ namespace Umbraco.Tests.TestHelpers var container = TestHelper.GetServiceCollection(); var typeLoader = TestHelper.GetMockedTypeLoader(); - var composition = new Composition(container, typeLoader, Mock.Of(), Mock.Of(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new UmbracoBuilder(container, Mock.Of()); + composition.TypeLoader = TestHelper.GetMockedTypeLoader(); composition.WithCollectionBuilder() .AddCoreMappers(); diff --git a/src/Umbraco.Tests.UnitTests/TestHelpers/CompositionExtensions.cs b/src/Umbraco.Tests.UnitTests/TestHelpers/CompositionExtensions.cs index 6a4f228070..7bbfed4e85 100644 --- a/src/Umbraco.Tests.UnitTests/TestHelpers/CompositionExtensions.cs +++ b/src/Umbraco.Tests.UnitTests/TestHelpers/CompositionExtensions.cs @@ -1,5 +1,6 @@ using System; using Microsoft.Extensions.DependencyInjection; +using Umbraco.Core.Builder; using Umbraco.Core.Composing; namespace Umbraco.Tests.UnitTests.TestHelpers @@ -7,10 +8,10 @@ namespace Umbraco.Tests.UnitTests.TestHelpers public static class CompositionExtensions { [Obsolete("This extension method exists only to ease migration, please refactor")] - public static IServiceProvider CreateServiceProvider(this Composition composition) + public static IServiceProvider CreateServiceProvider(this IUmbracoBuilder builder) { - composition.RegisterBuilders(); - return composition.Services.BuildServiceProvider(); + builder.Build(); + return builder.Services.BuildServiceProvider(); } } } diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Components/ComponentTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Components/ComponentTests.cs index f9cfef38c3..2fb493139c 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Components/ComponentTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Components/ComponentTests.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Microsoft.Extensions.Logging; @@ -9,6 +10,7 @@ using Microsoft.Extensions.Logging.Abstractions; using Moq; using NUnit.Framework; using Umbraco.Core; +using Umbraco.Core.Builder; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration.Models; @@ -19,6 +21,7 @@ using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Mappers; using Umbraco.Core.Scoping; using Umbraco.Tests.TestHelpers; +using Umbraco.Web.Common.Builder; namespace Umbraco.Tests.UnitTests.Umbraco.Core.Components { @@ -75,7 +78,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Components { var register = MockRegister(); var typeLoader = MockTypeLoader(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), Mock.Of(), IOHelper, AppCaches.NoCache); + var composition = new UmbracoBuilder(register, Mock.Of()); var types = TypeArray(); var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of>(), Mock.Of()); @@ -115,7 +118,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Components public void Boot1B() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), Mock.Of(x=>x.Level == RuntimeLevel.Run), IOHelper, AppCaches.NoCache); + var composition = new UmbracoBuilder(register, Mock.Of()); var types = TypeArray(); var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of>(), Mock.Of()); @@ -131,7 +134,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Components public void Boot2() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), Mock.Of(), IOHelper, AppCaches.NoCache); + var composition = new UmbracoBuilder(register, Mock.Of()); var types = TypeArray(); var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of>(), Mock.Of()); @@ -146,7 +149,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Components public void Boot3() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), Mock.Of(), IOHelper, AppCaches.NoCache); + var composition = new UmbracoBuilder(register, Mock.Of()); var types = TypeArray(); var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of>(), Mock.Of()); @@ -163,7 +166,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Components public void BrokenRequire() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), Mock.Of(), IOHelper, AppCaches.NoCache); + var composition = new UmbracoBuilder(register, Mock.Of()); var types = TypeArray(); var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of>(), Mock.Of()); @@ -186,7 +189,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Components public void BrokenRequired() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), Mock.Of(), IOHelper, AppCaches.NoCache); + var composition = new UmbracoBuilder(register, Mock.Of()); var types = TypeArray(); var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of>(), Mock.Of()); @@ -223,7 +226,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Components throw new NotSupportedException(type.FullName); }); }); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), Mock.Of(), IOHelper, AppCaches.NoCache); + var composition = new UmbracoBuilder(register, Mock.Of()); var types = new[] { typeof(Composer1), typeof(Composer5), typeof(Composer5a) }; var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of>(), Mock.Of()); @@ -249,7 +252,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Components public void Requires1() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), Mock.Of(), IOHelper, AppCaches.NoCache); + var composition = new UmbracoBuilder(register, Mock.Of()); var types = new[] { typeof(Composer6), typeof(Composer7), typeof(Composer8) }; var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of>(), Mock.Of()); @@ -264,7 +267,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Components public void Requires2A() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), Mock.Of(), IOHelper, AppCaches.NoCache); + var composition = new UmbracoBuilder(register, Mock.Of()); var types = new[] { typeof(Composer9), typeof(Composer2), typeof(Composer4) }; var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of>(), Mock.Of()); @@ -281,7 +284,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Components var register = MockRegister(); var typeLoader = MockTypeLoader(); var factory = MockFactory(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), Mock.Of(x=>x.Level == RuntimeLevel.Run), IOHelper, AppCaches.NoCache); + var composition = new UmbracoBuilder(register, Mock.Of()); var types = new[] { typeof(Composer9), typeof(Composer2), typeof(Composer4) }; var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of>(), Mock.Of()); @@ -300,7 +303,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Components public void WeakDependencies() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), Mock.Of(), IOHelper, AppCaches.NoCache); + var composition = new UmbracoBuilder(register, Mock.Of()); var types = new[] { typeof(Composer10) }; var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of>(), Mock.Of()); @@ -339,7 +342,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Components public void DisableMissing() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), Mock.Of(), IOHelper, AppCaches.NoCache); + var composition = new UmbracoBuilder(register, Mock.Of()); var types = new[] { typeof(Composer6), typeof(Composer8) }; // 8 disables 7 which is not in the list var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of>(), Mock.Of()); @@ -354,7 +357,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Components public void AttributesPriorities() { var register = MockRegister(); - var composition = new Composition(register, MockTypeLoader(), Mock.Of(), Mock.Of(), IOHelper, AppCaches.NoCache); + var composition = new UmbracoBuilder(register, Mock.Of()); var types = new[] { typeof(Composer26) }; var enableDisableAttributes = new[] { new DisableComposerAttribute(typeof(Composer26)) }; @@ -380,12 +383,12 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Components var typeLoader = new TypeLoader(typeFinder, AppCaches.Disabled.RuntimeCache, new DirectoryInfo(ioHelper.MapPath("~/App_Data/TEMP")), Mock.Of>(), Mock.Of()); var register = MockRegister(); - var composition = new Composition(register, typeLoader, Mock.Of(), - Mock.Of(), IOHelper, AppCaches.NoCache); + var builder = new UmbracoBuilder(register, Mock.Of()); + var allComposers = typeLoader.GetTypes().ToList(); var types = allComposers.Where(x => x.FullName.StartsWith("Umbraco.Core.") || x.FullName.StartsWith("Umbraco.Web")).ToList(); - var composers = new Composers(composition, types, Enumerable.Empty(), Mock.Of>(), Mock.Of()); + var composers = new Composers(builder, types, Enumerable.Empty(), Mock.Of>(), Mock.Of()); var requirements = composers.GetRequirements(); var report = Composers.GetComposersReport(requirements); Console.WriteLine(report); @@ -399,7 +402,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Components public class TestComposerBase : IComposer { - public virtual void Compose(Composition composition) + public virtual void Compose(IUmbracoBuilder builder) { Composed.Add(GetType()); } @@ -420,7 +423,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Components public class Composer5 : TestComposerBase { - public override void Compose(Composition composition) + public override void Compose(IUmbracoBuilder composition) { base.Compose(composition); composition.Components().Append(); @@ -430,10 +433,10 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Components [ComposeAfter(typeof(Composer5))] public class Composer5a : TestComposerBase { - public override void Compose(Composition composition) + public override void Compose(IUmbracoBuilder builder) { - base.Compose(composition); - composition.Components().Append(); + base.Compose(builder); + builder.Components().Append(); } } diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/CollectionBuildersTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/CollectionBuildersTests.cs index cb8a88c3ec..8ed3e2fdf6 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/CollectionBuildersTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/CollectionBuildersTests.cs @@ -1,28 +1,31 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Moq; using NUnit.Framework; using Umbraco.Core; +using Umbraco.Core.Builder; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Logging; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.UnitTests.TestHelpers; +using Umbraco.Web.Common.Builder; namespace Umbraco.Tests.UnitTests.Umbraco.Core.Composing { [TestFixture] public class CollectionBuildersTests { - private Composition _composition; + private IUmbracoBuilder _composition; [SetUp] public void Setup() { var register = TestHelper.GetServiceCollection(); - _composition = new Composition(register, TestHelper.GetMockedTypeLoader(), Mock.Of(), Mock.Of(), TestHelper.IOHelper, AppCaches.NoCache); + _composition = new UmbracoBuilder(register, Mock.Of()); } [TearDown] diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/LazyCollectionBuilderTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/LazyCollectionBuilderTests.cs index e0a8c28518..a6cb34f4e4 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/LazyCollectionBuilderTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/LazyCollectionBuilderTests.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Moq; using NUnit.Framework; @@ -10,6 +11,7 @@ using Umbraco.Core.Composing; using Umbraco.Core.Logging; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.UnitTests.TestHelpers; +using Umbraco.Web.Common.Builder; namespace Umbraco.Tests.UnitTests.Umbraco.Core.Composing { @@ -29,7 +31,8 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Composing public void LazyCollectionBuilderHandlesTypes() { var container = CreateRegister(); - var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), Mock.Of(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new UmbracoBuilder(container, Mock.Of()); + composition.TypeLoader = TestHelper.GetMockedTypeLoader(); composition.WithCollectionBuilder() .Add() @@ -55,7 +58,8 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Composing public void LazyCollectionBuilderHandlesProducers() { var container = CreateRegister(); - var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), Mock.Of(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new UmbracoBuilder(container, Mock.Of()); + composition.TypeLoader = TestHelper.GetMockedTypeLoader(); composition.WithCollectionBuilder() .Add(() => new[] { typeof(TransientObject3), typeof(TransientObject2) }) @@ -80,7 +84,8 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Composing public void LazyCollectionBuilderHandlesTypesAndProducers() { var container = CreateRegister(); - var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), Mock.Of(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new UmbracoBuilder(container, Mock.Of()); + composition.TypeLoader = TestHelper.GetMockedTypeLoader(); composition.WithCollectionBuilder() .Add() @@ -106,7 +111,8 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Composing public void LazyCollectionBuilderThrowsOnIllegalTypes() { var container = CreateRegister(); - var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), Mock.Of(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new UmbracoBuilder(container, Mock.Of()); + composition.TypeLoader = TestHelper.GetMockedTypeLoader(); composition.WithCollectionBuilder() .Add() @@ -128,7 +134,8 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Composing public void LazyCollectionBuilderCanExcludeTypes() { var container = CreateRegister(); - var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), Mock.Of(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new UmbracoBuilder(container, Mock.Of()); + composition.TypeLoader = TestHelper.GetMockedTypeLoader(); composition.WithCollectionBuilder() .Add() diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/PackageActionCollectionTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/PackageActionCollectionTests.cs index b13da91a96..efc22efb15 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/PackageActionCollectionTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/PackageActionCollectionTests.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Xml; using System.Xml.Linq; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Moq; using NUnit.Framework; @@ -12,6 +13,7 @@ using Umbraco.Core.Logging; using Umbraco.Core.PackageActions; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.UnitTests.TestHelpers; +using Umbraco.Web.Common.Builder; namespace Umbraco.Tests.UnitTests.Umbraco.Core.Composing { @@ -23,7 +25,8 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Core.Composing { var container = TestHelper.GetServiceCollection(); - var composition = new Composition(container, TestHelper.GetMockedTypeLoader(), Mock.Of(), Mock.Of(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new UmbracoBuilder(container, Mock.Of()); + composition.TypeLoader = TestHelper.GetMockedTypeLoader(); var expectedPackageActions = TypeLoader.GetPackageActions(); composition.WithCollectionBuilder() diff --git a/src/Umbraco.Tests/Cache/DistributedCacheBinderTests.cs b/src/Umbraco.Tests/Cache/DistributedCacheBinderTests.cs index 3598c75cf7..603e51c2eb 100644 --- a/src/Umbraco.Tests/Cache/DistributedCacheBinderTests.cs +++ b/src/Umbraco.Tests/Cache/DistributedCacheBinderTests.cs @@ -4,6 +4,7 @@ using System.Threading; using Moq; using NUnit.Framework; using Umbraco.Core; +using Umbraco.Core.Builder; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Events; @@ -26,13 +27,13 @@ namespace Umbraco.Tests.Cache [UmbracoTest(WithApplication = true)] public class DistributedCacheBinderTests : UmbracoTestBase { - protected override void Compose(Composition composition) + protected override void Compose(IUmbracoBuilder builder) { - base.Compose(composition); + base.Compose(builder); // refreshers.HandleEvents wants a UmbracoContext // which wants these - composition.Services.AddUnique(_ => Mock.Of()); - composition.WithCollectionBuilder(); + builder.Services.AddUnique(_ => Mock.Of()); + builder.WithCollectionBuilder(); } [Test] diff --git a/src/Umbraco.Tests/Cache/PublishedCache/PublishedMediaCacheTests.cs b/src/Umbraco.Tests/Cache/PublishedCache/PublishedMediaCacheTests.cs index cfcf7a82d8..2e377a0617 100644 --- a/src/Umbraco.Tests/Cache/PublishedCache/PublishedMediaCacheTests.cs +++ b/src/Umbraco.Tests/Cache/PublishedCache/PublishedMediaCacheTests.cs @@ -33,7 +33,7 @@ namespace Umbraco.Tests.Cache.PublishedCache { base.Compose(); - Composition.WithCollectionBuilder() + Builder.WithCollectionBuilder() .Clear() .Append(); diff --git a/src/Umbraco.Tests/IO/FileSystemsTests.cs b/src/Umbraco.Tests/IO/FileSystemsTests.cs index 8623b015a4..6ccfec9747 100644 --- a/src/Umbraco.Tests/IO/FileSystemsTests.cs +++ b/src/Umbraco.Tests/IO/FileSystemsTests.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Text; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; @@ -17,6 +18,7 @@ using Umbraco.Core.Logging; using Umbraco.Core.Services; using Umbraco.Tests.TestHelpers; using Umbraco.Web; +using Umbraco.Web.Common.Builder; using FileSystems = Umbraco.Core.IO.FileSystems; namespace Umbraco.Tests.IO @@ -32,14 +34,8 @@ namespace Umbraco.Tests.IO { _register = TestHelper.GetRegister(); - var composition = new Composition( - _register, - TestHelper.GetMockedTypeLoader(), - Mock.Of(), - Mock.Of(), - TestHelper.IOHelper, - AppCaches.NoCache - ); + var composition = new UmbracoBuilder(_register, Mock.Of()); + composition.TypeLoader = TestHelper.GetMockedTypeLoader(); composition.Services.AddTransient(_ => Mock.Of()); composition.Services.AddTransient(); diff --git a/src/Umbraco.Tests/Packaging/PackageDataInstallationTests.cs b/src/Umbraco.Tests/Packaging/PackageDataInstallationTests.cs index c94f9f5403..b48e3230f6 100644 --- a/src/Umbraco.Tests/Packaging/PackageDataInstallationTests.cs +++ b/src/Umbraco.Tests/Packaging/PackageDataInstallationTests.cs @@ -58,7 +58,7 @@ namespace Umbraco.Tests.Packaging // pollute everything, they are ignored by the type finder and explicitely // added to the editors collection - Composition.WithCollectionBuilder() + Builder.WithCollectionBuilder() .Add() .Add(); } @@ -70,7 +70,7 @@ namespace Umbraco.Tests.Packaging if (!withApplication) return; // re-register with actual media fs - Composition.ComposeFileSystems(); + Builder.ComposeFileSystems(); } private PackageDataInstallation PackageDataInstallation => Factory.GetRequiredService(); diff --git a/src/Umbraco.Tests/Published/ConvertersTests.cs b/src/Umbraco.Tests/Published/ConvertersTests.cs index 76e2c52978..7aaefd34c6 100644 --- a/src/Umbraco.Tests/Published/ConvertersTests.cs +++ b/src/Umbraco.Tests/Published/ConvertersTests.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; @@ -20,6 +21,7 @@ using Umbraco.Core.Strings; using Umbraco.Tests.PublishedContent; using Umbraco.Tests.TestHelpers; using Umbraco.Web; +using Umbraco.Web.Common.Builder; using Umbraco.Web.PublishedCache; namespace Umbraco.Tests.Published @@ -35,14 +37,8 @@ namespace Umbraco.Tests.Published // Current.Reset(); var register = TestHelper.GetRegister(); - var composition = new Composition( - register, - TestHelper.GetMockedTypeLoader(), - Mock.Of(), - Mock.Of(), - Mock.Of(), - AppCaches.NoCache - ); + var composition = new UmbracoBuilder(register, Mock.Of()); + composition.TypeLoader = TestHelper.GetMockedTypeLoader(); composition.WithCollectionBuilder() .Append() diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentLanguageVariantTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentLanguageVariantTests.cs index 547e7a637f..485e838a2b 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentLanguageVariantTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentLanguageVariantTests.cs @@ -24,7 +24,7 @@ namespace Umbraco.Tests.PublishedContent { base.Compose(); - Composition.Services.AddUnique(_ => GetServiceContext()); + Builder.Services.AddUnique(_ => GetServiceContext()); } protected ServiceContext GetServiceContext() diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentSnapshotTestBase.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentSnapshotTestBase.cs index c67382d093..75983ba41a 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentSnapshotTestBase.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentSnapshotTestBase.cs @@ -45,7 +45,7 @@ namespace Umbraco.Tests.PublishedContent { base.Compose(); - Composition.Services.AddUnique(f => new PublishedModelFactory(f.GetRequiredService().GetTypes(), f.GetRequiredService())); + Builder.Services.AddUnique(f => new PublishedModelFactory(f.GetRequiredService().GetTypes(), f.GetRequiredService())); } protected override TypeLoader CreateTypeLoader(IIOHelper ioHelper, ITypeFinder typeFinder, IAppPolicyCache runtimeCache, ILogger logger, IProfilingLogger profilingLogger , IHostingEnvironment hostingEnvironment) diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs index 0e7bdbc068..ea491194e2 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs @@ -34,7 +34,7 @@ namespace Umbraco.Tests.PublishedContent // FIXME: what about the if (PropertyValueConvertersResolver.HasCurrent == false) ?? // can we risk double - registering and then, what happens? - Composition.WithCollectionBuilder() + Builder.WithCollectionBuilder() .Clear() .Append() .Append() diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs index e75abf500d..e8144134fb 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs @@ -43,11 +43,11 @@ namespace Umbraco.Tests.PublishedContent { base.Compose(); _publishedSnapshotAccessorMock = new Mock(); - Composition.Services.AddUnique(_publishedSnapshotAccessorMock.Object); + Builder.Services.AddUnique(_publishedSnapshotAccessorMock.Object); - Composition.Services.AddUnique(f => new PublishedModelFactory(f.GetRequiredService().GetTypes(), f.GetRequiredService())); - Composition.Services.AddUnique(); - Composition.Services.AddUnique(); + Builder.Services.AddUnique(f => new PublishedModelFactory(f.GetRequiredService().GetTypes(), f.GetRequiredService())); + Builder.Services.AddUnique(); + Builder.Services.AddUnique(); var loggerFactory = NullLoggerFactory.Instance; var mediaService = Mock.Of(); @@ -68,7 +68,7 @@ namespace Umbraco.Tests.PublishedContent new DataType(new IntegerPropertyEditor(loggerFactory, Mock.Of(), localizationService, ShortStringHelper, LocalizedTextService), serializer) { Id = 1003 }, new DataType(new TextboxPropertyEditor(loggerFactory, Mock.Of(), localizationService, IOHelper, ShortStringHelper, LocalizedTextService), serializer) { Id = 1004 }, new DataType(new MediaPickerPropertyEditor(loggerFactory, Mock.Of(), localizationService, IOHelper, ShortStringHelper, LocalizedTextService), serializer) { Id = 1005 }); - Composition.Services.AddUnique(f => dataTypeService); + Builder.Services.AddUnique(f => dataTypeService); } protected override void Initialize() diff --git a/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs index c53cbea9e9..9262c72dfa 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs @@ -43,11 +43,11 @@ namespace Umbraco.Tests.PublishedContent { base.Compose(); - Composition.WithCollectionBuilder() + Builder.WithCollectionBuilder() .Clear() .Append(); - Composition.Services.AddUnique(); + Builder.Services.AddUnique(); } private IMediaType MakeNewMediaType(IUser user, string text, int parentId = -1) diff --git a/src/Umbraco.Tests/Routing/BaseUrlProviderTest.cs b/src/Umbraco.Tests/Routing/BaseUrlProviderTest.cs index 84e22c7760..d9c6021534 100644 --- a/src/Umbraco.Tests/Routing/BaseUrlProviderTest.cs +++ b/src/Umbraco.Tests/Routing/BaseUrlProviderTest.cs @@ -20,7 +20,7 @@ namespace Umbraco.Tests.Routing protected override void Compose() { base.Compose(); - Composition.Services.AddTransient(); + Builder.Services.AddTransient(); } protected override void ComposeSettings() @@ -28,8 +28,8 @@ namespace Umbraco.Tests.Routing var contentSettings = new ContentSettings(); var userPasswordConfigurationSettings = new UserPasswordConfigurationSettings(); - Composition.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(contentSettings)); - Composition.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(userPasswordConfigurationSettings)); + Builder.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(contentSettings)); + Builder.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(userPasswordConfigurationSettings)); } protected IPublishedUrlProvider GetPublishedUrlProvider(IUmbracoContext umbracoContext, DefaultUrlProvider urlProvider) diff --git a/src/Umbraco.Tests/Routing/DomainsAndCulturesTests.cs b/src/Umbraco.Tests/Routing/DomainsAndCulturesTests.cs index edcbf858e2..c51ca27b8c 100644 --- a/src/Umbraco.Tests/Routing/DomainsAndCulturesTests.cs +++ b/src/Umbraco.Tests/Routing/DomainsAndCulturesTests.cs @@ -15,7 +15,7 @@ namespace Umbraco.Tests.Routing { base.Compose(); - Composition.Services.AddTransient(); + Builder.Services.AddTransient(); } private void SetDomains1() diff --git a/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs b/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs index b3663738dd..0b2b793e74 100644 --- a/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs +++ b/src/Umbraco.Tests/Routing/RenderRouteHandlerTests.cs @@ -72,11 +72,11 @@ namespace Umbraco.Tests.Routing // var surfaceControllerTypes = new SurfaceControllerTypeCollection(Composition.TypeLoader.GetSurfaceControllers()); // Composition.Services.AddUnique(surfaceControllerTypes); - var umbracoApiControllerTypes = new UmbracoApiControllerTypeCollection(Composition.TypeLoader.GetUmbracoApiControllers()); - Composition.Services.AddUnique(umbracoApiControllerTypes); + var umbracoApiControllerTypes = new UmbracoApiControllerTypeCollection(Builder.TypeLoader.GetUmbracoApiControllers()); + Builder.Services.AddUnique(umbracoApiControllerTypes); var requestHandlerSettings = new RequestHandlerSettings(); - Composition.Services.AddUnique(_ => new DefaultShortStringHelper(Microsoft.Extensions.Options.Options.Create(requestHandlerSettings))); + Builder.Services.AddUnique(_ => new DefaultShortStringHelper(Microsoft.Extensions.Options.Options.Create(requestHandlerSettings))); } public override void TearDown() diff --git a/src/Umbraco.Tests/Routing/UrlProviderWithHideTopLevelNodeFromPathTests.cs b/src/Umbraco.Tests/Routing/UrlProviderWithHideTopLevelNodeFromPathTests.cs index eba88383e7..c403ade51c 100644 --- a/src/Umbraco.Tests/Routing/UrlProviderWithHideTopLevelNodeFromPathTests.cs +++ b/src/Umbraco.Tests/Routing/UrlProviderWithHideTopLevelNodeFromPathTests.cs @@ -28,7 +28,7 @@ namespace Umbraco.Tests.Routing protected override void ComposeSettings() { base.ComposeSettings(); - Composition.Services.AddUnique(x => Microsoft.Extensions.Options.Options.Create(_globalSettings)); + Builder.Services.AddUnique(x => Microsoft.Extensions.Options.Options.Create(_globalSettings)); } [TestCase(1046, "/")] diff --git a/src/Umbraco.Tests/Routing/UrlProviderWithoutHideTopLevelNodeFromPathTests.cs b/src/Umbraco.Tests/Routing/UrlProviderWithoutHideTopLevelNodeFromPathTests.cs index 9e0d311188..fd87ce84b1 100644 --- a/src/Umbraco.Tests/Routing/UrlProviderWithoutHideTopLevelNodeFromPathTests.cs +++ b/src/Umbraco.Tests/Routing/UrlProviderWithoutHideTopLevelNodeFromPathTests.cs @@ -34,7 +34,7 @@ namespace Umbraco.Tests.Routing protected override void ComposeSettings() { base.ComposeSettings(); - Composition.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(_globalSettings)); + Builder.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(_globalSettings)); } /// diff --git a/src/Umbraco.Tests/Routing/UrlRoutingTestBase.cs b/src/Umbraco.Tests/Routing/UrlRoutingTestBase.cs index 346af19a4c..192beee8a8 100644 --- a/src/Umbraco.Tests/Routing/UrlRoutingTestBase.cs +++ b/src/Umbraco.Tests/Routing/UrlRoutingTestBase.cs @@ -34,7 +34,7 @@ namespace Umbraco.Tests.Routing { base.Compose(); - Composition.Services.AddUnique(_ => GetServiceContext()); + Builder.Services.AddUnique(_ => GetServiceContext()); } protected ServiceContext GetServiceContext() diff --git a/src/Umbraco.Tests/Routing/UrlsProviderWithDomainsTests.cs b/src/Umbraco.Tests/Routing/UrlsProviderWithDomainsTests.cs index 5fef721dfa..49821c4318 100644 --- a/src/Umbraco.Tests/Routing/UrlsProviderWithDomainsTests.cs +++ b/src/Umbraco.Tests/Routing/UrlsProviderWithDomainsTests.cs @@ -25,8 +25,8 @@ namespace Umbraco.Tests.Routing { base.Compose(); - Composition.Services.AddUnique(_ => Mock.Of()); - Composition.Services.AddTransient(); + Builder.Services.AddUnique(_ => Mock.Of()); + Builder.Services.AddTransient(); } void SetDomains1() diff --git a/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs b/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs index f367db2123..5691599f81 100644 --- a/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs +++ b/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs @@ -27,8 +27,8 @@ namespace Umbraco.Tests.Routing protected override void Compose() { base.Compose(); - Composition.Services.AddUnique(_ => Mock.Of()); - Composition.Services.AddTransient(); + Builder.Services.AddUnique(_ => Mock.Of()); + Builder.Services.AddTransient(); } [Test] diff --git a/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs b/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs index 59f9a43526..e71187e9f3 100644 --- a/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopeEventDispatcherTests.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Logging; using Moq; @@ -20,6 +21,7 @@ using Umbraco.Tests.TestHelpers.Entities; using Umbraco.Web; using Current = Umbraco.Web.Composing.Current; using Microsoft.Extensions.DependencyInjection; +using Umbraco.Web.Common.Builder; namespace Umbraco.Tests.Scoping { @@ -38,7 +40,8 @@ namespace Umbraco.Tests.Scoping var services = TestHelper.GetRegister(); - var composition = new Composition(services, TestHelper.GetMockedTypeLoader(), Mock.Of(), Mock.Of(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new UmbracoBuilder(services, Mock.Of()); + composition.TypeLoader = TestHelper.GetMockedTypeLoader(); _testObjects = new TestObjects(services); diff --git a/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs b/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs index 5968a13ce8..f32ce9d9e1 100644 --- a/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs @@ -43,10 +43,10 @@ namespace Umbraco.Tests.Scoping // but then, it requires a lot of plumbing ;( // FIXME: and we cannot inject a DistributedCache yet // so doing all this mess - Composition.Services.AddUnique(); - Composition.Services.AddUnique(f => Mock.Of()); - Composition.WithCollectionBuilder() - .Add(() => Composition.TypeLoader.GetCacheRefreshers()); + Builder.Services.AddUnique(); + Builder.Services.AddUnique(f => Mock.Of()); + Builder.WithCollectionBuilder() + .Add(() => Builder.TypeLoader.GetCacheRefreshers()); } public override void TearDown() diff --git a/src/Umbraco.Tests/Scoping/ScopedXmlTests.cs b/src/Umbraco.Tests/Scoping/ScopedXmlTests.cs index 3a07a9864a..6814210cc4 100644 --- a/src/Umbraco.Tests/Scoping/ScopedXmlTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopedXmlTests.cs @@ -38,10 +38,10 @@ namespace Umbraco.Tests.Scoping // but then, it requires a lot of plumbing ;( // FIXME: and we cannot inject a DistributedCache yet // so doing all this mess - Composition.Services.AddUnique(); - Composition.Services.AddUnique(f => Mock.Of()); - Composition.WithCollectionBuilder() - .Add(() => Composition.TypeLoader.GetCacheRefreshers()); + Builder.Services.AddUnique(); + Builder.Services.AddUnique(f => Mock.Of()); + Builder.WithCollectionBuilder() + .Add(() => Builder.TypeLoader.GetCacheRefreshers()); } protected override void ComposeSettings() @@ -50,9 +50,9 @@ namespace Umbraco.Tests.Scoping var globalSettings = new GlobalSettings(); var userPasswordConfigurationSettings = new UserPasswordConfigurationSettings(); - Composition.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(contentSettings)); - Composition.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(globalSettings)); - Composition.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(userPasswordConfigurationSettings)); + Builder.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(contentSettings)); + Builder.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(globalSettings)); + Builder.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(userPasswordConfigurationSettings)); } [TearDown] diff --git a/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs b/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs index ddfc6fa7f1..17d38e723d 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseUsingSqlCeSyntax.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Moq; using NPoco; @@ -14,6 +15,7 @@ using Umbraco.Core.Persistence.Mappers; using Umbraco.Core.Persistence; using Umbraco.Persistance.SqlCe; using Umbraco.Web; +using Umbraco.Web.Common.Builder; using Current = Umbraco.Web.Composing.Current; namespace Umbraco.Tests.TestHelpers @@ -46,7 +48,8 @@ namespace Umbraco.Tests.TestHelpers logger, false); - var composition = new Composition(services, typeLoader, Mock.Of(), Mock.Of(), TestHelper.IOHelper, AppCaches.NoCache); + var composition = new UmbracoBuilder(services, Mock.Of()); + composition.TypeLoader = TestHelper.GetMockedTypeLoader(); services.AddUnique(_ => Mock.Of()); services.AddUnique(_ => NullLoggerFactory.Instance); diff --git a/src/Umbraco.Tests/TestHelpers/BaseWebTest.cs b/src/Umbraco.Tests/TestHelpers/BaseWebTest.cs index eaa186bef6..34ffeebd1e 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseWebTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseWebTest.cs @@ -37,8 +37,8 @@ namespace Umbraco.Tests.TestHelpers { base.Compose(); - Composition.Services.AddUnique(); - Composition.Services.AddUnique(); + Builder.Services.AddUnique(); + Builder.Services.AddUnique(); } protected override void Initialize() diff --git a/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs b/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs index 53a7e7ba36..faf387528d 100644 --- a/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs +++ b/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs @@ -73,18 +73,18 @@ namespace Umbraco.Tests.TestHelpers { base.Compose(); - Composition.Services.AddTransient(); - Composition.Services.AddTransient(factory => PublishedSnapshotService); - Composition.Services.AddTransient(factory => DefaultCultureAccessor); + Builder.Services.AddTransient(); + Builder.Services.AddTransient(factory => PublishedSnapshotService); + Builder.Services.AddTransient(factory => DefaultCultureAccessor); - Composition.WithCollectionBuilder() + Builder.WithCollectionBuilder() .Clear() - .Add(() => Composition.TypeLoader.GetDataEditors()); + .Add(() => Builder.TypeLoader.GetDataEditors()); - Composition.WithCollectionBuilder() - .Add(Composition.TypeLoader.GetUmbracoApiControllers()); + Builder.WithCollectionBuilder() + .Add(Builder.TypeLoader.GetUmbracoApiControllers()); - Composition.Services.AddUnique(f => + Builder.Services.AddUnique(f => { if (Options.Database == UmbracoTestOptions.Database.None) return TestObjects.GetDatabaseFactoryMock(); diff --git a/src/Umbraco.Tests/Testing/TestingTests/MockTests.cs b/src/Umbraco.Tests/Testing/TestingTests/MockTests.cs index 9c259d7d16..cb48020db0 100644 --- a/src/Umbraco.Tests/Testing/TestingTests/MockTests.cs +++ b/src/Umbraco.Tests/Testing/TestingTests/MockTests.cs @@ -63,11 +63,11 @@ namespace Umbraco.Tests.Testing.TestingTests public void Can_Mock_Umbraco_Helper() { // unless we can inject them in MembershipHelper, we need need this - Composition.Services.AddTransient(_ => Mock.Of()); - Composition.Services.AddTransient(_ => Mock.Of()); - Composition.Services.AddTransient(_ => Mock.Of()); - Composition.Services.AddTransient(_ => AppCaches.Disabled); - Composition.Services.AddTransient(); + Builder.Services.AddTransient(_ => Mock.Of()); + Builder.Services.AddTransient(_ => Mock.Of()); + Builder.Services.AddTransient(_ => Mock.Of()); + Builder.Services.AddTransient(_ => AppCaches.Disabled); + Builder.Services.AddTransient(); // ReSharper disable once UnusedVariable var helper = new UmbracoHelper(Mock.Of(), diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index 4466b9424e..cc30b33002 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -9,6 +9,7 @@ using System.Web.Routing; using System.Web.Security; using System.Xml.Linq; using Examine; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; @@ -16,6 +17,7 @@ using Moq; using NUnit.Framework; using Serilog; using Umbraco.Core; +using Umbraco.Core.Builder; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Composing.CompositionExtensions; @@ -50,6 +52,7 @@ using Umbraco.Tests.TestHelpers.Stubs; using Umbraco.Web; using Umbraco.Web.Actions; using Umbraco.Web.AspNet; +using Umbraco.Web.Common.Builder; using Umbraco.Web.ContentApps; using Umbraco.Web.Hosting; using Umbraco.Web.Install; @@ -103,7 +106,7 @@ namespace Umbraco.Tests.Testing // test feature, and no test "base" class should be. only actual test feature classes // should be marked with that attribute. - protected Composition Composition { get; private set; } + protected IUmbracoBuilder Builder { get; private set; } protected IServiceProvider Factory { get; private set; } @@ -205,14 +208,10 @@ namespace Umbraco.Tests.Testing var services = TestHelper.GetRegister(); - Composition = new Composition( - services, - typeLoader, - proflogger, - MockRuntimeState(RuntimeLevel.Run), - TestHelper.IOHelper, - AppCaches.NoCache - ); + Builder = new UmbracoBuilder(services, Mock.Of()) + { + TypeLoader = typeLoader + }; //TestHelper.GetConfigs().RegisterWith(register); services.AddUnique(typeof(ILoggerFactory), loggerFactory); @@ -248,7 +247,7 @@ namespace Umbraco.Tests.Testing TestObjects = new TestObjects(services); Compose(); - Current.Factory = Factory = Composition.CreateServiceProvider(); + Current.Factory = Factory = Builder.CreateServiceProvider(); Initialize(); } @@ -263,10 +262,10 @@ namespace Umbraco.Tests.Testing ComposeMisc(); // not sure really - Compose(Composition); + Compose(Builder); } - protected virtual void Compose(Composition composition) + protected virtual void Compose(IUmbracoBuilder builder) { } protected virtual void Initialize() @@ -312,19 +311,19 @@ namespace Umbraco.Tests.Testing Umbraco.Web.Composing.Current.UmbracoContextAccessor = new TestUmbracoContextAccessor(); // web - Composition.Services.AddUnique(_ => Umbraco.Web.Composing.Current.UmbracoContextAccessor); - Composition.Services.AddUnique(); - Composition.WithCollectionBuilder(); + Builder.Services.AddUnique(_ => Umbraco.Web.Composing.Current.UmbracoContextAccessor); + Builder.Services.AddUnique(); + Builder.WithCollectionBuilder(); - Composition.DataValueReferenceFactories(); + Builder.DataValueReferenceFactories(); - Composition.Services.AddUnique(); - Composition.Services.AddUnique(); - Composition.Services.AddUnique(); - Composition.SetCultureDictionaryFactory(); - Composition.Services.AddSingleton(f => f.GetRequiredService().CreateDictionary()); + Builder.Services.AddUnique(); + Builder.Services.AddUnique(); + Builder.Services.AddUnique(); + Builder.SetCultureDictionaryFactory(); + Builder.Services.AddSingleton(f => f.GetRequiredService().CreateDictionary()); // register back office sections in the order we want them rendered - Composition.WithCollectionBuilder().Append() + Builder.WithCollectionBuilder().Append() .Append() .Append() .Append() @@ -332,18 +331,18 @@ namespace Umbraco.Tests.Testing .Append() .Append() .Append(); - Composition.Services.AddUnique(); + Builder.Services.AddUnique(); - Composition.Services.AddUnique(); - Composition.Services.AddUnique(); - Composition.Services.AddUnique(); - Composition.Services.AddUnique(); - Composition.Services.AddUnique(); - Composition.Services.AddUnique(); - Composition.Services.AddUnique(); + Builder.Services.AddUnique(); + Builder.Services.AddUnique(); + Builder.Services.AddUnique(); + Builder.Services.AddUnique(); + Builder.Services.AddUnique(); + Builder.Services.AddUnique(); + Builder.Services.AddUnique(); var webRoutingSettings = new WebRoutingSettings(); - Composition.Services.AddUnique(factory => + Builder.Services.AddUnique(factory => new UrlProvider( factory.GetRequiredService(), Microsoft.Extensions.Options.Options.Create(webRoutingSettings), @@ -360,25 +359,25 @@ namespace Umbraco.Tests.Testing // what else? var runtimeStateMock = new Mock(); runtimeStateMock.Setup(x => x.Level).Returns(RuntimeLevel.Run); - Composition.Services.AddUnique(f => runtimeStateMock.Object); - Composition.Services.AddTransient(_ => Mock.Of()); - Composition.Services.AddTransient(); + Builder.Services.AddUnique(f => runtimeStateMock.Object); + Builder.Services.AddTransient(_ => Mock.Of()); + Builder.Services.AddTransient(); // ah... - Composition.WithCollectionBuilder(); - Composition.WithCollectionBuilder(); - Composition.Services.AddUnique(); - Composition.Services.AddUnique(); + Builder.WithCollectionBuilder(); + Builder.WithCollectionBuilder(); + Builder.Services.AddUnique(); + Builder.Services.AddUnique(); - Composition.Services.AddUnique(); + Builder.Services.AddUnique(); // register empty content apps collection - Composition.WithCollectionBuilder(); + Builder.WithCollectionBuilder(); // manifest - Composition.ManifestValueValidators(); - Composition.ManifestFilters(); - Composition.MediaUrlGenerators() + Builder.ManifestValueValidators(); + Builder.ManifestFilters(); + Builder.MediaUrlGenerators() .Add() .Add(); @@ -388,7 +387,7 @@ namespace Umbraco.Tests.Testing { if (configure == false) return; - Composition + Builder .ComposeCoreMappingProfiles(); } @@ -442,13 +441,13 @@ namespace Umbraco.Tests.Testing var userPasswordConfigurationSettings = new UserPasswordConfigurationSettings(); var webRoutingSettings = new WebRoutingSettings(); - Composition.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(contentSettings)); - Composition.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(coreDebugSettings)); - Composition.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(globalSettings)); - Composition.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(nuCacheSettings)); - Composition.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(requestHandlerSettings)); - Composition.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(userPasswordConfigurationSettings)); - Composition.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(webRoutingSettings)); + Builder.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(contentSettings)); + Builder.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(coreDebugSettings)); + Builder.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(globalSettings)); + Builder.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(nuCacheSettings)); + Builder.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(requestHandlerSettings)); + Builder.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(userPasswordConfigurationSettings)); + Builder.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(webRoutingSettings)); } protected virtual void ComposeApplication(bool withApplication) @@ -458,69 +457,69 @@ namespace Umbraco.Tests.Testing if (withApplication == false) return; // default Datalayer/Repositories/SQL/Database/etc... - Composition.ComposeRepositories(); + Builder.ComposeRepositories(); - Composition.Services.AddUnique(); + Builder.Services.AddUnique(); - Composition.Services.AddUnique(); - Composition.Services.AddUnique(); - Composition.Services.AddUnique(); - Composition.Services.AddUnique(); + Builder.Services.AddUnique(); + Builder.Services.AddUnique(); + Builder.Services.AddUnique(); + Builder.Services.AddUnique(); // register filesystems - Composition.Services.AddUnique(factory => TestObjects.GetFileSystemsMock()); + Builder.Services.AddUnique(factory => TestObjects.GetFileSystemsMock()); var scheme = Mock.Of(); var mediaFileSystem = new MediaFileSystem(Mock.Of(), scheme, _loggerFactory.CreateLogger(), TestHelper.ShortStringHelper); - Composition.Services.AddUnique(factory => mediaFileSystem); + Builder.Services.AddUnique(factory => mediaFileSystem); // no factory (noop) - Composition.Services.AddUnique(); + Builder.Services.AddUnique(); // register application stuff (database factory & context, services...) - Composition.WithCollectionBuilder() + Builder.WithCollectionBuilder() .AddCoreMappers(); - Composition.Services.AddUnique(_ => new TransientEventMessagesFactory()); + Builder.Services.AddUnique(_ => new TransientEventMessagesFactory()); var globalSettings = new GlobalSettings(); var connectionStrings = new ConnectionStrings(); - Composition.Services.AddUnique(f => new UmbracoDatabaseFactory(_loggerFactory.CreateLogger(), + Builder.Services.AddUnique(f => new UmbracoDatabaseFactory(_loggerFactory.CreateLogger(), LoggerFactory, globalSettings, connectionStrings, new Lazy(f.GetRequiredService), TestHelper.DbProviderFactoryCreator)); - Composition.Services.AddUnique(f => f.GetService().SqlContext); + Builder.Services.AddUnique(f => f.GetService().SqlContext); - Composition.WithCollectionBuilder(); // empty + Builder.WithCollectionBuilder(); // empty - Composition.Services.AddUnique(factory + Builder.Services.AddUnique(factory => TestObjects.GetScopeProvider(_loggerFactory, factory.GetService(), factory.GetService(), factory.GetService())); - Composition.Services.AddUnique(factory => (IScopeAccessor) factory.GetRequiredService()); + Builder.Services.AddUnique(factory => (IScopeAccessor) factory.GetRequiredService()); - Composition.ComposeServices(); + Builder.ComposeServices(); // composition root is doing weird things, fix - Composition.Services.AddUnique(); - Composition.Services.AddUnique(); + Builder.Services.AddUnique(); + Builder.Services.AddUnique(); // somehow property editor ends up wanting this - Composition.WithCollectionBuilder(); + Builder.WithCollectionBuilder(); - Composition.Services.AddUnique(); + Builder.Services.AddUnique(); // note - don't register collections, use builders - Composition.WithCollectionBuilder(); - Composition.Services.AddUnique(); - Composition.Services.AddUnique(); + Builder.WithCollectionBuilder(); + Builder.Services.AddUnique(); + Builder.Services.AddUnique(); - Composition.Services.AddUnique(TestHelper.GetHttpContextAccessor(GetHttpContextFactory("/").HttpContext)); + Builder.Services.AddUnique(TestHelper.GetHttpContextAccessor(GetHttpContextFactory("/").HttpContext)); } #endregion diff --git a/src/Umbraco.Tests/UmbracoExamine/ExamineBaseTest.cs b/src/Umbraco.Tests/UmbracoExamine/ExamineBaseTest.cs index ab8884cbaf..62e352bf15 100644 --- a/src/Umbraco.Tests/UmbracoExamine/ExamineBaseTest.cs +++ b/src/Umbraco.Tests/UmbracoExamine/ExamineBaseTest.cs @@ -35,7 +35,7 @@ namespace Umbraco.Tests.UmbracoExamine { base.Compose(); var requestHandlerSettings = new RequestHandlerSettings(); - Composition.Services.AddUnique(_ => new DefaultShortStringHelper(Microsoft.Extensions.Options.Options.Create(requestHandlerSettings))); + Builder.Services.AddUnique(_ => new DefaultShortStringHelper(Microsoft.Extensions.Options.Options.Create(requestHandlerSettings))); } } } diff --git a/src/Umbraco.Tests/Web/Controllers/AuthenticationControllerTests.cs b/src/Umbraco.Tests/Web/Controllers/AuthenticationControllerTests.cs index 0cb990df3d..cdc2bfed00 100644 --- a/src/Umbraco.Tests/Web/Controllers/AuthenticationControllerTests.cs +++ b/src/Umbraco.Tests/Web/Controllers/AuthenticationControllerTests.cs @@ -51,12 +51,12 @@ namespace Umbraco.Tests.Web.Controllers // replace the true IUserService implementation with a mock // so that each test can configure the service to their liking - Composition.Services.AddUnique(f => Mock.Of()); + Builder.Services.AddUnique(f => Mock.Of()); // kill the true IEntityService too - Composition.Services.AddUnique(f => Mock.Of()); + Builder.Services.AddUnique(f => Mock.Of()); - Composition.Services.AddUnique(); + Builder.Services.AddUnique(); } diff --git a/src/Umbraco.Web.BackOffice/Extensions/CompositionExtensions.cs b/src/Umbraco.Web.BackOffice/Extensions/CompositionExtensions.cs index 2a8a2e900d..4e8fe01b7f 100644 --- a/src/Umbraco.Web.BackOffice/Extensions/CompositionExtensions.cs +++ b/src/Umbraco.Web.BackOffice/Extensions/CompositionExtensions.cs @@ -1,4 +1,5 @@ -using Umbraco.Core.Composing; +using Umbraco.Core.Builder; +using Umbraco.Core.Composing; using Umbraco.Web.BackOffice.Trees; // the namespace here is intentional - although defined in Umbraco.Web assembly, @@ -18,10 +19,10 @@ namespace Umbraco.Extensions /// /// Gets the back office tree collection builder /// - /// + /// /// - public static TreeCollectionBuilder Trees(this Composition composition) - => composition.WithCollectionBuilder(); + public static TreeCollectionBuilder Trees(this IUmbracoBuilder builder) + => builder.WithCollectionBuilder(); #endregion } diff --git a/src/Umbraco.Web.BackOffice/Extensions/UmbracoBuilderExtensions.cs b/src/Umbraco.Web.BackOffice/Extensions/UmbracoBuilderExtensions.cs index c494425274..12e5f39299 100644 --- a/src/Umbraco.Web.BackOffice/Extensions/UmbracoBuilderExtensions.cs +++ b/src/Umbraco.Web.BackOffice/Extensions/UmbracoBuilderExtensions.cs @@ -1,14 +1,16 @@ -using Umbraco.Web.Common.Builder; +using Microsoft.AspNetCore.Hosting; +using Umbraco.Core.Builder; +using Umbraco.Web.Common.Builder; namespace Umbraco.Extensions { public static class UmbracoBuilderExtensions { - public static IUmbracoBuilder WithAllBackOfficeComponents(this IUmbracoBuilder builder) + public static IUmbracoBuilder WithAllBackOfficeComponents(this IUmbracoBuilder builder, IWebHostEnvironment webHostEnvironment) { return builder .WithConfiguration() - .WithCore() + .WithCore(webHostEnvironment) .WithWebComponents() .WithRuntimeMinifier() .WithBackOffice() diff --git a/src/Umbraco.Web.BackOffice/Extensions/WebMappingProfiles.cs b/src/Umbraco.Web.BackOffice/Extensions/WebMappingProfiles.cs index bc72b1dd44..600ff101fe 100644 --- a/src/Umbraco.Web.BackOffice/Extensions/WebMappingProfiles.cs +++ b/src/Umbraco.Web.BackOffice/Extensions/WebMappingProfiles.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.DependencyInjection; using Umbraco.Core; using Umbraco.Core.BackOffice; +using Umbraco.Core.Builder; using Umbraco.Core.Composing; using Umbraco.Core.Mapping; using Umbraco.Web.BackOffice.Mapping; @@ -9,16 +10,16 @@ namespace Umbraco.Extensions { public static class WebMappingProfiles { - public static Composition ComposeWebMappingProfiles(this Composition composition) + public static IUmbracoBuilder ComposeWebMappingProfiles(this IUmbracoBuilder builder) { - composition.WithCollectionBuilder() + builder.WithCollectionBuilder() .Add() .Add() .Add(); - composition.Services.AddTransient(); + builder.Services.AddTransient(); - return composition; + return builder; } } } diff --git a/src/Umbraco.Web.BackOffice/Runtime/BackOfficeComposer.cs b/src/Umbraco.Web.BackOffice/Runtime/BackOfficeComposer.cs index fb6b015520..d11dffb1ac 100644 --- a/src/Umbraco.Web.BackOffice/Runtime/BackOfficeComposer.cs +++ b/src/Umbraco.Web.BackOffice/Runtime/BackOfficeComposer.cs @@ -2,6 +2,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Umbraco.Core; +using Umbraco.Core.Builder; using Umbraco.Core.Composing; using Umbraco.Core.Hosting; using Umbraco.Core.IO; @@ -22,36 +23,36 @@ namespace Umbraco.Web.BackOffice.Runtime [ComposeAfter(typeof(AspNetCoreComposer))] public class BackOfficeComposer : IComposer { - public void Compose(Composition composition) + public void Compose(IUmbracoBuilder builder) { - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddScoped(); - composition.Services.AddScoped(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddScoped(); + builder.Services.AddScoped(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); // register back office trees // the collection builder only accepts types inheriting from TreeControllerBase // and will filter out those that are not attributed with TreeAttribute - var umbracoApiControllerTypes = composition.TypeLoader.GetUmbracoApiControllers().ToList(); - composition.Trees() + var umbracoApiControllerTypes = builder.TypeLoader.GetUmbracoApiControllers().ToList(); + builder.Trees() .AddTreeControllers(umbracoApiControllerTypes.Where(x => typeof(TreeControllerBase).IsAssignableFrom(x))); - composition.ComposeWebMappingProfiles(); + builder.ComposeWebMappingProfiles(); - composition.Services.AddUnique(factory => + builder.Services.AddUnique(factory => new PhysicalFileSystem( factory.GetRequiredService(), factory.GetRequiredService(), factory.GetRequiredService>(), "~/")); - composition.Services.AddUnique(); - composition.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); } } } diff --git a/src/Umbraco.Web.BackOffice/SignalR/PreviewHubComposer.cs b/src/Umbraco.Web.BackOffice/SignalR/PreviewHubComposer.cs index de40340e6f..e994571c90 100644 --- a/src/Umbraco.Web.BackOffice/SignalR/PreviewHubComposer.cs +++ b/src/Umbraco.Web.BackOffice/SignalR/PreviewHubComposer.cs @@ -1,13 +1,14 @@ using Umbraco.Core; +using Umbraco.Core.Builder; using Umbraco.Core.Composing; namespace Umbraco.Web.BackOffice.SignalR { public class PreviewHubComposer : ComponentComposer, ICoreComposer { - public override void Compose(Composition composition) + public override void Compose(IUmbracoBuilder builder) { - base.Compose(composition); + base.Compose(builder); } } } diff --git a/src/Umbraco.Web.Common/Builder/UmbracoBuilderExtensions.cs b/src/Umbraco.Web.Common/Builder/UmbracoBuilderExtensions.cs index 10f214a522..7072916aa0 100644 --- a/src/Umbraco.Web.Common/Builder/UmbracoBuilderExtensions.cs +++ b/src/Umbraco.Web.Common/Builder/UmbracoBuilderExtensions.cs @@ -5,7 +5,9 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using System; +using Microsoft.Extensions.Logging; using Umbraco.Core; +using Umbraco.Core.Builder; using Umbraco.Extensions; using Umbraco.Web.Common.Filters; using Umbraco.Web.Common.ModelBinders; @@ -15,23 +17,27 @@ namespace Umbraco.Web.Common.Builder // TODO: We could add parameters to configure each of these for flexibility public static class UmbracoBuilderExtensions { - public static IUmbracoBuilder AddUmbraco(this IServiceCollection services, IWebHostEnvironment webHostEnvironment, IConfiguration config) + public static IUmbracoBuilder AddUmbraco( + this IServiceCollection services, + IConfiguration config) { if (services is null) throw new ArgumentNullException(nameof(services)); - if (webHostEnvironment is null) throw new ArgumentNullException(nameof(webHostEnvironment)); if (config is null) throw new ArgumentNullException(nameof(config)); services.AddLazySupport(); - var builder = new UmbracoBuilder(services, webHostEnvironment, config); + var builder = new UmbracoBuilder(services, config); return builder; } public static IUmbracoBuilder WithConfiguration(this IUmbracoBuilder builder) => builder.AddWith(nameof(WithConfiguration), () => builder.Services.AddUmbracoConfiguration(builder.Config)); - public static IUmbracoBuilder WithCore(this IUmbracoBuilder builder) - => builder.AddWith(nameof(WithCore), () => builder.Services.AddUmbracoCore(builder.WebHostEnvironment, builder.Config)); + public static IUmbracoBuilder WithCore(this IUmbracoBuilder builder, IWebHostEnvironment webHostEnvironment) + => builder.AddWith(nameof(WithCore), () => + { + builder.AddUmbracoCore(webHostEnvironment, builder.Config); + }); public static IUmbracoBuilder WithHostedServices(this IUmbracoBuilder builder) => builder.AddWith(nameof(WithHostedServices), () => builder.Services.AddUmbracoHostedServices()); diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs index c98cbca39e..954d84bd43 100644 --- a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs @@ -13,6 +13,7 @@ using Microsoft.Extensions.Options; using Serilog; using Serilog.Extensions.Hosting; using Umbraco.Core; +using Umbraco.Core.Builder; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; @@ -79,27 +80,6 @@ namespace Umbraco.Extensions return services; } - /// - /// Adds the Umbraco Back Core requirements - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public static IServiceCollection AddUmbracoCore(this IServiceCollection services, - IWebHostEnvironment webHostEnvironment, - Assembly entryAssembly, - AppCaches appCaches, - ILoggingConfiguration loggingConfiguration, - IConfiguration configuration) - => services.AddUmbracoCore(webHostEnvironment, entryAssembly, appCaches, loggingConfiguration, configuration, GetCoreRuntime); - /// /// Adds the Umbraco Back Core requirements /// @@ -108,14 +88,13 @@ namespace Umbraco.Extensions /// /// /// - public static IServiceCollection AddUmbracoCore(this IServiceCollection services, IWebHostEnvironment webHostEnvironment, IConfiguration configuration) + public static IUmbracoBuilder AddUmbracoCore(this IUmbracoBuilder builder, IWebHostEnvironment webHostEnvironment, IConfiguration configuration) { - var loggingConfig = new LoggingConfiguration( - Path.Combine(webHostEnvironment.ContentRootPath, "umbraco", "logs")); + var loggingConfig = new LoggingConfiguration(Path.Combine(webHostEnvironment.ContentRootPath, "umbraco", "logs")); IHttpContextAccessor httpContextAccessor = new HttpContextAccessor(); - services.AddSingleton(httpContextAccessor); - services.AddSingleton(loggingConfig); + builder.Services.AddSingleton(httpContextAccessor); + builder.Services.AddSingleton(loggingConfig); var requestCache = new GenericDictionaryRequestAppCache(() => httpContextAccessor.HttpContext?.Items); var appCaches = new AppCaches( @@ -123,14 +102,14 @@ namespace Umbraco.Extensions requestCache, new IsolatedCaches(type => new DeepCloneAppCache(new ObjectCacheAppCache()))); - services.AddUmbracoCore(webHostEnvironment, + builder.AddUmbracoCore(webHostEnvironment, Assembly.GetEntryAssembly(), appCaches, loggingConfig, configuration, GetCoreRuntime); - return services; + return builder; } /// @@ -146,8 +125,8 @@ namespace Umbraco.Extensions /// Delegate to create an /// /// - public static IServiceCollection AddUmbracoCore( - this IServiceCollection services, + public static IUmbracoBuilder AddUmbracoCore( + this IUmbracoBuilder builder, IWebHostEnvironment webHostEnvironment, Assembly entryAssembly, AppCaches appCaches, @@ -156,25 +135,25 @@ namespace Umbraco.Extensions //TODO: Yep that's extremely ugly Func getRuntimeBootstrapper) { - if (services is null) throw new ArgumentNullException(nameof(services)); + if (builder is null) throw new ArgumentNullException(nameof(builder)); if (entryAssembly is null) throw new ArgumentNullException(nameof(entryAssembly)); - services.AddLazySupport(); + builder.Services.AddLazySupport(); // Add service session // This can be overwritten by the user by adding their own call to AddSession // since the last call of AddSession take precedence - services.AddSession(options => + builder.Services.AddSession(options => { options.Cookie.Name = "UMB_SESSION"; options.Cookie.HttpOnly = true; }); // Add supported databases - services.AddUmbracoSqlCeSupport(); - services.AddUmbracoSqlServerSupport(); + builder.Services.AddUmbracoSqlCeSupport(); + builder.Services.AddUmbracoSqlServerSupport(); - services.AddSingleton(x => new DbProviderFactoryCreator( + builder.Services.AddSingleton(x => new DbProviderFactoryCreator( DbProviderFactories.GetFactory, x.GetServices(), x.GetServices(), @@ -188,7 +167,7 @@ namespace Umbraco.Extensions // it will be the same instance resolved later because we are re-registering this instance back // into the container. This is not true for `Configs` but we should do that too, see comments in // `RegisterEssentials`. - var serviceProvider = services.BuildServiceProvider(); + var serviceProvider = builder.Services.BuildServiceProvider(); var globalSettings = serviceProvider.GetService>(); var connectionStrings = serviceProvider.GetService>(); @@ -197,14 +176,13 @@ namespace Umbraco.Extensions var dbProviderFactoryCreator = serviceProvider.GetRequiredService(); - CreateCompositionRoot(services, - globalSettings, - hostingSettings, - webHostEnvironment, - loggingConfiguration, - configuration, out var ioHelper, out var hostingEnvironment, out var backOfficeInfo, out var profiler); + var hostingEnvironment = new AspNetCoreHostingEnvironment(hostingSettings, webHostEnvironment); + var ioHelper = new IOHelper(hostingEnvironment); + var backOfficeInfo = new AspNetCoreBackOfficeInfo(globalSettings); + var profiler = GetWebProfiler(hostingEnvironment); - var loggerFactory = services.BuildServiceProvider().GetService(); + builder.Services.AddLogger(hostingEnvironment, loggingConfiguration, configuration); + var loggerFactory = builder.Services.BuildServiceProvider().GetService(); var umbracoVersion = new UmbracoVersion(); var typeFinder = CreateTypeFinder(loggerFactory, profiler, webHostEnvironment, entryAssembly, typeFinderSettings); @@ -222,9 +200,9 @@ namespace Umbraco.Extensions appCaches, dbProviderFactoryCreator); - bootstrapper.Configure(services); + bootstrapper.Configure(builder); - return services; + return builder; } /// @@ -324,7 +302,7 @@ namespace Umbraco.Extensions return new TypeFinder(loggerFactory.CreateLogger(), new DefaultUmbracoAssemblyProvider(entryAssembly), runtimeHash, new TypeFinderConfig(typeFinderSettings)); } - private static CoreRuntimeBootstrapper GetCoreRuntime( + internal static CoreRuntimeBootstrapper GetCoreRuntime( GlobalSettings globalSettings, ConnectionStrings connectionStrings, IUmbracoVersion umbracoVersion, IIOHelper ioHelper, ILoggerFactory loggerFactory, IProfiler profiler, IHostingEnvironment hostingEnvironment, IBackOfficeInfo backOfficeInfo, ITypeFinder typeFinder, AppCaches appCaches, IDbProviderFactoryCreator dbProviderFactoryCreator) @@ -357,36 +335,13 @@ namespace Umbraco.Extensions return coreRuntime; } - private static IServiceCollection CreateCompositionRoot( - IServiceCollection services, - IOptionsMonitor globalSettings, - IOptionsMonitor hostingSettings, - IWebHostEnvironment webHostEnvironment, - ILoggingConfiguration loggingConfiguration, - IConfiguration configuration, - out IIOHelper ioHelper, - out Core.Hosting.IHostingEnvironment hostingEnvironment, - out IBackOfficeInfo backOfficeInfo, - out IProfiler profiler) - { - if (globalSettings == null) - throw new InvalidOperationException($"Could not resolve type {typeof(GlobalSettings)} from the container, ensure {nameof(AddUmbracoConfiguration)} is called before calling {nameof(AddUmbracoCore)}"); - - hostingEnvironment = new AspNetCoreHostingEnvironment(hostingSettings, webHostEnvironment); - ioHelper = new IOHelper(hostingEnvironment); - AddLogger(services, hostingEnvironment, loggingConfiguration, configuration); - backOfficeInfo = new AspNetCoreBackOfficeInfo(globalSettings); - profiler = GetWebProfiler(hostingEnvironment); - - return services; - } /// /// Create and configure the logger /// /// - private static void AddLogger( - IServiceCollection services, + public static IServiceCollection AddLogger( + this IServiceCollection services, IHostingEnvironment hostingEnvironment, ILoggingConfiguration loggingConfiguration, IConfiguration configuration) @@ -420,6 +375,8 @@ namespace Umbraco.Extensions // Consumed by user code services.AddSingleton(diagnosticContext); + + return services; } private static IProfiler GetWebProfiler(Umbraco.Core.Hosting.IHostingEnvironment hostingEnvironment) diff --git a/src/Umbraco.Web.Common/Profiler/WebProfilerComposer.cs b/src/Umbraco.Web.Common/Profiler/WebProfilerComposer.cs index fd8f275291..702c30f692 100644 --- a/src/Umbraco.Web.Common/Profiler/WebProfilerComposer.cs +++ b/src/Umbraco.Web.Common/Profiler/WebProfilerComposer.cs @@ -1,15 +1,16 @@ using Umbraco.Core; +using Umbraco.Core.Builder; using Umbraco.Core.Composing; namespace Umbraco.Web.Common.Profiler { internal class WebProfilerComposer : ComponentComposer, ICoreComposer { - public override void Compose(Composition composition) + public override void Compose(IUmbracoBuilder builder) { - base.Compose(composition); + base.Compose(builder); - composition.Services.AddUnique(); + builder.Services.AddUnique(); } } } diff --git a/src/Umbraco.Web.Common/Runtime/AspNetCoreBootFailedComposer.cs b/src/Umbraco.Web.Common/Runtime/AspNetCoreBootFailedComposer.cs index 196b115618..58fa5ea317 100644 --- a/src/Umbraco.Web.Common/Runtime/AspNetCoreBootFailedComposer.cs +++ b/src/Umbraco.Web.Common/Runtime/AspNetCoreBootFailedComposer.cs @@ -1,4 +1,5 @@ using Umbraco.Core; +using Umbraco.Core.Builder; using Umbraco.Core.Composing; using Umbraco.Web.Common.Middleware; @@ -9,9 +10,9 @@ namespace Umbraco.Web.Common.Runtime /// public class AspNetCoreBootFailedComposer : IComposer { - public void Compose(Composition composition) + public void Compose(IUmbracoBuilder builder) { - composition.Services.AddUnique(); + builder.Services.AddUnique(); } } } diff --git a/src/Umbraco.Web.Common/Runtime/AspNetCoreComposer.cs b/src/Umbraco.Web.Common/Runtime/AspNetCoreComposer.cs index 8acea23289..6308588c10 100644 --- a/src/Umbraco.Web.Common/Runtime/AspNetCoreComposer.cs +++ b/src/Umbraco.Web.Common/Runtime/AspNetCoreComposer.cs @@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Umbraco.Core; +using Umbraco.Core.Builder; using Umbraco.Core.Composing; using Umbraco.Core.Configuration.Models; using Umbraco.Core.Diagnostics; @@ -40,62 +41,62 @@ namespace Umbraco.Web.Common.Runtime [ComposeAfter(typeof(CoreInitialComposer))] public class AspNetCoreComposer : ComponentComposer, IComposer { - public override void Compose(Composition composition) + public override void Compose(IUmbracoBuilder builder) { - base.Compose(composition); + base.Compose(builder); // AspNetCore specific services - composition.Services.AddUnique(); - composition.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); // Our own netcore implementations - composition.Services.AddMultipleUnique(); + builder.Services.AddMultipleUnique(); - composition.Services.AddUnique(); + builder.Services.AddUnique(); // The umbraco request lifetime - composition.Services.AddMultipleUnique(); + builder.Services.AddMultipleUnique(); // Password hasher - composition.Services.AddUnique(); + builder.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddTransient(); - composition.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddTransient(); + builder.Services.AddUnique(); - composition.Services.AddMultipleUnique(); + builder.Services.AddMultipleUnique(); - composition.Services.AddUnique(); + builder.Services.AddUnique(); - composition.Services.AddUnique(); + builder.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); // register the umbraco context factory - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); //register the install components - composition.ComposeInstaller(); + builder.ComposeInstaller(); - var umbracoApiControllerTypes = composition.TypeLoader.GetUmbracoApiControllers().ToList(); - composition.WithCollectionBuilder() + var umbracoApiControllerTypes = builder.TypeLoader.GetUmbracoApiControllers().ToList(); + builder.WithCollectionBuilder() .Add(umbracoApiControllerTypes); - composition.Services.AddUnique(); + builder.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); - composition.Services.AddUnique(); + builder.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddUnique(factory => new LegacyPasswordSecurity()); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddUnique(factory => new LegacyPasswordSecurity()); } } } diff --git a/src/Umbraco.Web.Common/RuntimeMinification/SmidgeComposer.cs b/src/Umbraco.Web.Common/RuntimeMinification/SmidgeComposer.cs index 3400ee49d9..5b3d776679 100644 --- a/src/Umbraco.Web.Common/RuntimeMinification/SmidgeComposer.cs +++ b/src/Umbraco.Web.Common/RuntimeMinification/SmidgeComposer.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.DependencyInjection; using Smidge.FileProcessors; using Umbraco.Core; +using Umbraco.Core.Builder; using Umbraco.Core.Composing; using Umbraco.Core.Runtime; using Umbraco.Core.WebAssets; @@ -9,14 +10,14 @@ namespace Umbraco.Web.Common.RuntimeMinification { public sealed class SmidgeComposer : IComposer { - public void Compose(Composition composition) + public void Compose(IUmbracoBuilder builder) { // TODO: For this to work we need to have services.AddSmidge() based on the Smidge APIs but our composer APIs don't really let us do that // This makes it a bit awkward to boot the runtime since that call would need to be made outside of the composer... .hrm... - composition.Services.AddUnique(); - composition.Services.AddUnique(); - composition.Services.AddTransient(); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddTransient(); } } } diff --git a/src/Umbraco.Web.Common/Umbraco.Web.Common.csproj b/src/Umbraco.Web.Common/Umbraco.Web.Common.csproj index a712a43a45..5e4f4eeb98 100644 --- a/src/Umbraco.Web.Common/Umbraco.Web.Common.csproj +++ b/src/Umbraco.Web.Common/Umbraco.Web.Common.csproj @@ -34,6 +34,9 @@ <_Parameter1>Umbraco.Tests.UnitTests + + <_Parameter1>Umbraco.Tests.Integration + diff --git a/src/Umbraco.Web.UI.NetCore/Startup.cs b/src/Umbraco.Web.UI.NetCore/Startup.cs index 2a4d4a4580..a2918aa340 100644 --- a/src/Umbraco.Web.UI.NetCore/Startup.cs +++ b/src/Umbraco.Web.UI.NetCore/Startup.cs @@ -32,9 +32,9 @@ namespace Umbraco.Web.UI.NetCore // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { - var umbracoBuilder = services.AddUmbraco(_env, _config); + var umbracoBuilder = services.AddUmbraco(_config); umbracoBuilder - .WithAllBackOfficeComponents() + .WithAllBackOfficeComponents(_env) .WithAllWebsiteComponents() .Build(); diff --git a/src/Umbraco.Web.Website/Extensions/UmbracoBuilderExtensions.cs b/src/Umbraco.Web.Website/Extensions/UmbracoBuilderExtensions.cs index 8e56cd6dca..4e22fa55c8 100644 --- a/src/Umbraco.Web.Website/Extensions/UmbracoBuilderExtensions.cs +++ b/src/Umbraco.Web.Website/Extensions/UmbracoBuilderExtensions.cs @@ -1,4 +1,5 @@ -using Umbraco.Web.Common.Builder; +using Umbraco.Core.Builder; +using Umbraco.Web.Common.Builder; namespace Umbraco.Extensions { diff --git a/src/Umbraco.Web.Website/Runtime/WebsiteComposer.cs b/src/Umbraco.Web.Website/Runtime/WebsiteComposer.cs index 055b146a51..ce3ff7271e 100644 --- a/src/Umbraco.Web.Website/Runtime/WebsiteComposer.cs +++ b/src/Umbraco.Web.Website/Runtime/WebsiteComposer.cs @@ -1,4 +1,5 @@ using Umbraco.Core; +using Umbraco.Core.Builder; using Umbraco.Core.Composing; using Umbraco.Extensions; using Umbraco.Web.Website.Routing; @@ -12,12 +13,12 @@ namespace Umbraco.Web.Website.Runtime [ComposeAfter(typeof(AspNetCoreComposer))] public class WebsiteComposer : IComposer { - public void Compose(Composition composition) + public void Compose(IUmbracoBuilder builder) { - composition.Services.AddUnique(); + builder.Services.AddUnique(); - composition.WithCollectionBuilder() - .Add(composition.TypeLoader.GetSurfaceControllers()); + builder.WithCollectionBuilder() + .Add(builder.TypeLoader.GetSurfaceControllers()); } } } diff --git a/src/Umbraco.Web/CompositionExtensions.cs b/src/Umbraco.Web/CompositionExtensions.cs index d96e21aa3d..7768f3fc1b 100644 --- a/src/Umbraco.Web/CompositionExtensions.cs +++ b/src/Umbraco.Web/CompositionExtensions.cs @@ -1,6 +1,7 @@ using System; using Microsoft.Extensions.DependencyInjection; using Umbraco.Core; +using Umbraco.Core.Builder; using Umbraco.Core.Composing; using Umbraco.Web.Actions; using Umbraco.Web.ContentApps; @@ -19,21 +20,21 @@ using Current = Umbraco.Web.Composing.Current; // the namespace here is intentional - although defined in Umbraco.Web assembly, // this class should be visible when using Umbraco.Core.Components, alongside -// Umbraco.Core's own CompositionExtensions class +// Umbraco.Core's own IUmbracoBuilderExtensions class // ReSharper disable once CheckNamespace namespace Umbraco.Web { /// - /// Provides extension methods to the class. + /// Provides extension methods to the class. /// - public static class WebCompositionExtensions + public static class WebIUmbracoBuilderExtensions { [Obsolete("This extension method exists only to ease migration, please refactor")] - public static IServiceProvider CreateServiceProvider(this Composition composition) + public static IServiceProvider CreateServiceProvider(this IUmbracoBuilder builder) { - composition.RegisterBuilders(); - return composition.Services.BuildServiceProvider(); + builder.Build(); + return builder.Services.BuildServiceProvider(); } #region Uniques @@ -42,62 +43,62 @@ namespace Umbraco.Web /// Sets the content last chance finder. /// /// The type of the content last chance finder. - /// The composition. - public static void SetContentLastChanceFinder(this Composition composition) + /// The builder. + public static void SetContentLastChanceFinder(this IUmbracoBuilder builder) where T : class, IContentLastChanceFinder { - composition.Services.AddUnique(); + builder.Services.AddUnique(); } /// /// Sets the content last chance finder. /// - /// The composition. + /// The builder. /// A function creating a last chance finder. - public static void SetContentLastChanceFinder(this Composition composition, Func factory) + public static void SetContentLastChanceFinder(this IUmbracoBuilder builder, Func factory) { - composition.Services.AddUnique(factory); + builder.Services.AddUnique(factory); } /// /// Sets the content last chance finder. /// - /// The composition. + /// The builder. /// A last chance finder. - public static void SetContentLastChanceFinder(this Composition composition, IContentLastChanceFinder finder) + public static void SetContentLastChanceFinder(this IUmbracoBuilder builder, IContentLastChanceFinder finder) { - composition.Services.AddUnique(_ => finder); + builder.Services.AddUnique(_ => finder); } /// /// Sets the site domain helper. /// /// The type of the site domain helper. - /// - public static void SetSiteDomainHelper(this Composition composition) + /// + public static void SetSiteDomainHelper(this IUmbracoBuilder builder) where T : class, ISiteDomainHelper { - composition.Services.AddUnique(); + builder.Services.AddUnique(); } /// /// Sets the site domain helper. /// - /// The composition. + /// The builder. /// A function creating a helper. - public static void SetSiteDomainHelper(this Composition composition, Func factory) + public static void SetSiteDomainHelper(this IUmbracoBuilder builder, Func factory) { - composition.Services.AddUnique(factory); + builder.Services.AddUnique(factory); } /// /// Sets the site domain helper. /// - /// The composition. + /// The builder. /// A helper. - public static void SetSiteDomainHelper(this Composition composition, ISiteDomainHelper helper) + public static void SetSiteDomainHelper(this IUmbracoBuilder builder, ISiteDomainHelper helper) { - composition.Services.AddUnique(_ => helper); + builder.Services.AddUnique(_ => helper); } #endregion diff --git a/src/Umbraco.Web/Runtime/WebInitialComposer.cs b/src/Umbraco.Web/Runtime/WebInitialComposer.cs index 32e7835ffb..0d866363c4 100644 --- a/src/Umbraco.Web/Runtime/WebInitialComposer.cs +++ b/src/Umbraco.Web/Runtime/WebInitialComposer.cs @@ -3,6 +3,7 @@ using System.Web.Security; using Microsoft.AspNet.SignalR; using Microsoft.Extensions.DependencyInjection; using Umbraco.Core; +using Umbraco.Core.Builder; using Umbraco.Core.Composing; using Umbraco.Core.Dictionary; using Umbraco.Core.Templates; @@ -23,36 +24,36 @@ namespace Umbraco.Web.Runtime [ComposeBefore(typeof(ICoreComposer))] public sealed class WebInitialComposer : ComponentComposer { - public override void Compose(Composition composition) + public override void Compose(IUmbracoBuilder builder) { - base.Compose(composition); + base.Compose(builder); - composition.Services.AddTransient(); + builder.Services.AddTransient(); // register membership stuff - composition.Services.AddTransient(factory => MembershipProviderExtensions.GetMembersMembershipProvider()); - composition.Services.AddTransient(factory => Roles.Enabled ? Roles.Provider : new MembersRoleProvider(factory.GetRequiredService())); - composition.Services.AddScoped(); - composition.Services.AddTransient(factory => factory.GetRequiredService().PublishedSnapshot.Members); - composition.Services.AddUnique(); - composition.Services.AddUnique(); + builder.Services.AddTransient(factory => MembershipProviderExtensions.GetMembersMembershipProvider()); + builder.Services.AddTransient(factory => Roles.Enabled ? Roles.Provider : new MembersRoleProvider(factory.GetRequiredService())); + builder.Services.AddScoped(); + builder.Services.AddTransient(factory => factory.GetRequiredService().PublishedSnapshot.Members); + builder.Services.AddUnique(); + builder.Services.AddUnique(); + builder.Services.AddTransient(factory => + { + var state = factory.GetRequiredService(); - // register the umbraco helper - this is Transient! very important! - // also, if not level.Run, we cannot really use the helper (during upgrade...) - // so inject a "void" helper (not exactly pretty but...) - if (composition.RuntimeState.Level == RuntimeLevel.Run) - composition.Services.AddTransient(factory => + if (state.Level == RuntimeLevel.Run) { var umbCtx = factory.GetRequiredService(); return new UmbracoHelper(umbCtx.IsFrontEndUmbracoRequest ? umbCtx.PublishedRequest?.PublishedContent : null, factory.GetRequiredService(), factory.GetRequiredService(), factory.GetRequiredService()); - }); - else - composition.Services.AddTransient(_ => new UmbracoHelper()); + } - composition.Services.AddUnique(); + return new UmbracoHelper(); + }); + + builder.Services.AddUnique(); // configure the container for web //composition.ConfigureForWeb(); diff --git a/src/Umbraco.Web/WebAssets/CDF/ClientDependencyComposer.cs b/src/Umbraco.Web/WebAssets/CDF/ClientDependencyComposer.cs index bb8c2be059..c591191524 100644 --- a/src/Umbraco.Web/WebAssets/CDF/ClientDependencyComposer.cs +++ b/src/Umbraco.Web/WebAssets/CDF/ClientDependencyComposer.cs @@ -1,4 +1,5 @@ using Umbraco.Core; +using Umbraco.Core.Builder; using Umbraco.Core.Composing; using Umbraco.Core.WebAssets; @@ -6,10 +7,10 @@ namespace Umbraco.Web.WebAssets.CDF { public sealed class ClientDependencyComposer : ComponentComposer { - public override void Compose(Composition composition) + public override void Compose(IUmbracoBuilder builder) { - base.Compose(composition); - composition.Services.AddUnique(); + base.Compose(builder); + builder.Services.AddUnique(); } } }