2012-08-01 22:06:15 +06:00
|
|
|
|
using System;
|
2013-07-01 14:23:56 +10:00
|
|
|
|
using System.Linq;
|
2015-01-21 12:48:08 +11:00
|
|
|
|
using System.Threading.Tasks;
|
2013-07-01 14:23:56 +10:00
|
|
|
|
using AutoMapper;
|
2013-08-09 11:37:57 +10:00
|
|
|
|
using Umbraco.Core.Cache;
|
2012-12-15 08:41:46 +05:00
|
|
|
|
using Umbraco.Core.Configuration;
|
2015-01-21 12:48:08 +11:00
|
|
|
|
using Umbraco.Core.Configuration.UmbracoSettings;
|
|
|
|
|
|
using Umbraco.Core.IO;
|
|
|
|
|
|
using Umbraco.Core.LightInject;
|
2012-08-01 22:06:15 +06:00
|
|
|
|
using Umbraco.Core.Logging;
|
2013-07-01 14:23:56 +10:00
|
|
|
|
using Umbraco.Core.Models.Mapping;
|
2013-09-13 21:15:40 +02:00
|
|
|
|
using Umbraco.Core.Models.PublishedContent;
|
2012-08-10 13:18:13 +06:00
|
|
|
|
using Umbraco.Core.ObjectResolution;
|
2012-12-09 09:01:00 +05:00
|
|
|
|
using Umbraco.Core.Persistence;
|
2012-12-29 18:53:13 -01:00
|
|
|
|
using Umbraco.Core.Persistence.Mappers;
|
2013-01-10 04:33:30 +03:00
|
|
|
|
using Umbraco.Core.Persistence.Migrations;
|
2013-03-09 10:43:34 -01:00
|
|
|
|
using Umbraco.Core.Persistence.SqlSyntax;
|
2012-12-14 08:06:32 +05:00
|
|
|
|
using Umbraco.Core.Persistence.UnitOfWork;
|
2013-05-12 15:25:46 -10:00
|
|
|
|
using Umbraco.Core.Profiling;
|
2012-08-18 11:39:18 +06:00
|
|
|
|
using Umbraco.Core.PropertyEditors;
|
2012-12-14 08:06:32 +05:00
|
|
|
|
using Umbraco.Core.Publishing;
|
2013-01-16 13:31:04 -01:00
|
|
|
|
using Umbraco.Core.Macros;
|
2012-12-14 08:06:32 +05:00
|
|
|
|
using Umbraco.Core.Services;
|
2013-02-11 20:07:23 +06:00
|
|
|
|
using Umbraco.Core.Sync;
|
2013-02-07 13:30:50 -01:00
|
|
|
|
using Umbraco.Core.Strings;
|
2015-01-21 12:48:08 +11:00
|
|
|
|
|
2012-08-01 22:06:15 +06:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Core
|
|
|
|
|
|
{
|
2015-01-21 12:48:08 +11:00
|
|
|
|
|
2013-06-20 10:05:51 +10:00
|
|
|
|
/// <summary>
|
2015-01-07 17:23:24 +11:00
|
|
|
|
/// A bootstrapper for the Umbraco application which initializes all objects for the Core of the application
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// This does not provide any startup functionality relating to web objects
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
public class CoreBootManager : IBootManager
|
|
|
|
|
|
{
|
2015-01-21 13:21:36 +11:00
|
|
|
|
|
2015-01-21 12:48:08 +11:00
|
|
|
|
private ServiceContainer _appStartupEvtContainer;
|
|
|
|
|
|
protected ProfilingLogger ProfilingLogger { get; private set; }
|
2015-01-07 17:23:24 +11:00
|
|
|
|
private DisposableTimer _timer;
|
2015-01-21 12:48:08 +11:00
|
|
|
|
protected PluginManager PluginManager { get; private set; }
|
|
|
|
|
|
private CacheHelper _cacheHelper;
|
|
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
private bool _isInitialized = false;
|
|
|
|
|
|
private bool _isStarted = false;
|
|
|
|
|
|
private bool _isComplete = false;
|
2013-01-29 09:45:12 +06:00
|
|
|
|
private readonly UmbracoApplicationBase _umbracoApplication;
|
2015-01-21 12:48:08 +11:00
|
|
|
|
|
|
|
|
|
|
protected ApplicationContext ApplicationContext { get; private set; }
|
2012-08-14 12:03:34 +06:00
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
protected UmbracoApplicationBase UmbracoApplication
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return _umbracoApplication; }
|
|
|
|
|
|
}
|
2013-01-29 09:45:12 +06:00
|
|
|
|
|
2015-01-21 13:21:36 +11:00
|
|
|
|
internal ServiceContainer Container
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return _umbracoApplication.Container; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-01-21 12:48:08 +11:00
|
|
|
|
protected IServiceProvider ServiceProvider { get; private set; }
|
2013-01-29 09:45:12 +06:00
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
public CoreBootManager(UmbracoApplicationBase umbracoApplication)
|
|
|
|
|
|
{
|
2013-01-29 09:45:12 +06:00
|
|
|
|
if (umbracoApplication == null) throw new ArgumentNullException("umbracoApplication");
|
2015-01-21 13:21:36 +11:00
|
|
|
|
_umbracoApplication = umbracoApplication;
|
2013-01-29 09:45:12 +06:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
public virtual IBootManager Initialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_isInitialized)
|
|
|
|
|
|
throw new InvalidOperationException("The boot manager has already been initialized");
|
2012-08-07 21:40:34 +06:00
|
|
|
|
|
2015-01-21 12:48:08 +11:00
|
|
|
|
//Create logger/profiler, and their resolvers, these are special resolvers that can be resolved before frozen so we can start logging
|
2015-01-21 13:21:36 +11:00
|
|
|
|
LoggerResolver.Current = new LoggerResolver(_umbracoApplication.Logger) { CanResolveBeforeFrozen = true };
|
2015-01-21 12:48:08 +11:00
|
|
|
|
var profiler = CreateProfiler();
|
|
|
|
|
|
ProfilerResolver.Current = new ProfilerResolver(profiler) {CanResolveBeforeFrozen = true};
|
2015-01-21 13:21:36 +11:00
|
|
|
|
ProfilingLogger = new ProfilingLogger(_umbracoApplication.Logger, profiler);
|
2013-05-13 21:11:03 -10:00
|
|
|
|
|
2015-01-21 12:48:08 +11:00
|
|
|
|
_timer = ProfilingLogger.DebugDuration<CoreBootManager>("Umbraco application starting", "Umbraco application startup complete");
|
2015-01-16 12:29:27 +11:00
|
|
|
|
|
2015-01-21 12:48:08 +11:00
|
|
|
|
//create the plugin manager
|
|
|
|
|
|
//TODO: this is currently a singleton but it would be better if it weren't. Unfortunately the only way to get
|
|
|
|
|
|
// rid of this singleton would be to put it into IoC and then use the ServiceLocator pattern.
|
|
|
|
|
|
_cacheHelper = CreateApplicationCache();
|
|
|
|
|
|
ServiceProvider = new ActivatorServiceProvider();
|
|
|
|
|
|
PluginManager.Current = PluginManager = new PluginManager(ServiceProvider, _cacheHelper.RuntimeCache, ProfilingLogger, true);
|
2015-01-07 17:23:24 +11:00
|
|
|
|
|
2015-01-21 13:21:36 +11:00
|
|
|
|
//build up core IoC servoces
|
|
|
|
|
|
ConfigureCoreServices(Container);
|
2013-07-02 17:47:20 +10:00
|
|
|
|
|
2015-01-21 12:48:08 +11:00
|
|
|
|
//set the singleton resolved from the core container
|
|
|
|
|
|
ApplicationContext.Current = ApplicationContext = Container.GetInstance<ApplicationContext>();
|
2013-07-02 17:47:20 +10:00
|
|
|
|
|
2015-01-21 12:48:08 +11:00
|
|
|
|
//TODO: Remove these for v8!
|
2013-09-09 15:57:22 +10:00
|
|
|
|
LegacyPropertyEditorIdToAliasConverter.CreateMappingsForCoreEditors();
|
2013-10-30 14:36:07 +11:00
|
|
|
|
LegacyParameterEditorAliasConverter.CreateMappingsForCoreEditors();
|
2015-01-21 12:48:08 +11:00
|
|
|
|
//TODO: Make this as part of the db ctor!
|
2015-01-07 17:23:24 +11:00
|
|
|
|
Database.Mapper = new PetaPocoMapper();
|
2015-01-13 18:19:52 +11:00
|
|
|
|
|
2015-01-21 12:48:08 +11:00
|
|
|
|
//Create a 'child'container which is a copy of all of the current registrations and begin a sub scope for it
|
|
|
|
|
|
// this child container will be used to manage the application event handler instances and the scope will be
|
|
|
|
|
|
// completed at the end of the boot process to allow garbage collection
|
|
|
|
|
|
_appStartupEvtContainer = Container.CreateChildContainer();
|
|
|
|
|
|
_appStartupEvtContainer.BeginScope();
|
|
|
|
|
|
_appStartupEvtContainer.RegisterCollection<IApplicationEventHandler, PerScopeLifetime>(PluginManager.ResolveApplicationStartupHandlers());
|
2015-01-21 13:21:36 +11:00
|
|
|
|
|
|
|
|
|
|
//build up standard IoC services
|
2015-01-21 12:48:08 +11:00
|
|
|
|
ConfigureServices(Container);
|
2015-01-21 13:21:36 +11:00
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
InitializeResolvers();
|
2013-06-18 17:22:01 +10:00
|
|
|
|
InitializeModelMappers();
|
|
|
|
|
|
|
2013-01-29 09:45:12 +06:00
|
|
|
|
//now we need to call the initialize methods
|
2015-01-21 12:48:08 +11:00
|
|
|
|
Parallel.ForEach(_appStartupEvtContainer.GetAllInstances<IApplicationEventHandler>(), x => x.OnApplicationInitialized(UmbracoApplication, ApplicationContext));
|
2013-01-29 09:45:12 +06:00
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
_isInitialized = true;
|
2012-08-07 21:40:34 +06:00
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
return this;
|
|
|
|
|
|
}
|
2012-08-01 22:06:15 +06:00
|
|
|
|
|
2013-03-11 23:46:47 +06:00
|
|
|
|
/// <summary>
|
2015-01-21 12:48:08 +11:00
|
|
|
|
/// Build the core container which contains all core things requird to build an app context
|
|
|
|
|
|
/// </summary>
|
2015-01-21 13:21:36 +11:00
|
|
|
|
private void ConfigureCoreServices(ServiceContainer container)
|
2015-01-21 12:48:08 +11:00
|
|
|
|
{
|
2015-01-21 13:21:36 +11:00
|
|
|
|
container.Register<ILogger>(factory => _umbracoApplication.Logger, new PerContainerLifetime());
|
|
|
|
|
|
container.Register<IProfiler>(factory => ProfilingLogger.Profiler, new PerContainerLifetime());
|
|
|
|
|
|
container.Register<ProfilingLogger>(factory => ProfilingLogger, new PerContainerLifetime());
|
2015-01-21 12:48:08 +11:00
|
|
|
|
container.Register<IUmbracoSettingsSection>(factory => UmbracoConfig.For.UmbracoSettings());
|
|
|
|
|
|
container.Register<CacheHelper>(factory => _cacheHelper, new PerContainerLifetime());
|
|
|
|
|
|
container.Register<IRuntimeCacheProvider>(factory => _cacheHelper.RuntimeCache, new PerContainerLifetime());
|
|
|
|
|
|
container.Register<IServiceProvider, ActivatorServiceProvider>();
|
|
|
|
|
|
container.Register<PluginManager>(factory => PluginManager, new PerContainerLifetime());
|
|
|
|
|
|
container.Register<IDatabaseFactory>(factory => new DefaultDatabaseFactory(GlobalSettings.UmbracoConnectionName, factory.GetInstance<ILogger>()));
|
|
|
|
|
|
container.Register<DatabaseContext>(factory => GetDbContext(factory), new PerContainerLifetime());
|
|
|
|
|
|
container.Register<SqlSyntaxProviders>(factory => SqlSyntaxProviders.CreateDefault(factory.GetInstance<ILogger>()));
|
|
|
|
|
|
container.Register<IDatabaseUnitOfWorkProvider, PetaPocoUnitOfWorkProvider>();
|
|
|
|
|
|
container.Register<IUnitOfWorkProvider, FileUnitOfWorkProvider>();
|
|
|
|
|
|
container.Register<BasePublishingStrategy, PublishingStrategy>();
|
|
|
|
|
|
container.Register<RepositoryFactory>();
|
|
|
|
|
|
container.Register<ServiceContext>(factory => new ServiceContext(
|
|
|
|
|
|
factory.GetInstance<RepositoryFactory>(),
|
|
|
|
|
|
factory.GetInstance<IDatabaseUnitOfWorkProvider>(),
|
|
|
|
|
|
factory.GetInstance<IUnitOfWorkProvider>(),
|
|
|
|
|
|
factory.GetInstance<BasePublishingStrategy>(),
|
|
|
|
|
|
factory.GetInstance<CacheHelper>(),
|
|
|
|
|
|
factory.GetInstance<ILogger>()));
|
|
|
|
|
|
container.Register<ApplicationContext>(new PerContainerLifetime());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Called to customize the IoC container
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="container"></param>
|
|
|
|
|
|
internal virtual void ConfigureServices(ServiceContainer container)
|
|
|
|
|
|
{
|
|
|
|
|
|
container.Register<MediaFileSystem>(factory => FileSystemProviderManager.Current.GetFileSystemProvider<MediaFileSystem>());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Creates and initializes the db context when IoC requests it
|
2013-03-11 23:46:47 +06:00
|
|
|
|
/// </summary>
|
2015-01-21 12:48:08 +11:00
|
|
|
|
/// <param name="container"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
private DatabaseContext GetDbContext(IServiceFactory container)
|
2013-03-11 23:46:47 +06:00
|
|
|
|
{
|
2015-01-21 12:48:08 +11:00
|
|
|
|
var dbCtx = new DatabaseContext(
|
|
|
|
|
|
container.GetInstance<IDatabaseFactory>(),
|
|
|
|
|
|
container.GetInstance<ILogger>(),
|
|
|
|
|
|
container.GetInstance<SqlSyntaxProviders>());
|
|
|
|
|
|
|
|
|
|
|
|
//when it's first created we need to initialize it
|
|
|
|
|
|
dbCtx.Initialize();
|
|
|
|
|
|
return dbCtx;
|
2013-07-02 17:47:20 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2015-01-21 12:48:08 +11:00
|
|
|
|
/// Creates the ApplicationCache based on a new instance of System.Web.Caching.Cache
|
2013-07-02 17:47:20 +10:00
|
|
|
|
/// </summary>
|
2015-01-21 12:48:08 +11:00
|
|
|
|
protected virtual CacheHelper CreateApplicationCache()
|
2013-07-02 17:47:20 +10:00
|
|
|
|
{
|
2013-08-09 11:37:57 +10:00
|
|
|
|
var cacheHelper = new CacheHelper(
|
2015-01-21 12:48:08 +11:00
|
|
|
|
new ObjectCacheRuntimeCacheProvider(),
|
|
|
|
|
|
new StaticCacheProvider(),
|
2015-01-07 17:23:24 +11:00
|
|
|
|
//we have no request based cache when not running in web-based context
|
2015-01-21 12:48:08 +11:00
|
|
|
|
new NullCacheProvider());
|
2013-08-09 11:37:57 +10:00
|
|
|
|
|
2015-01-21 12:48:08 +11:00
|
|
|
|
return cacheHelper;
|
2013-03-11 23:46:47 +06:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-06-18 17:22:01 +10:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// This method allows for configuration of model mappers
|
|
|
|
|
|
/// </summary>
|
2013-07-01 14:23:56 +10:00
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// Model mappers MUST be defined on ApplicationEventHandler instances with the interface IMapperConfiguration.
|
|
|
|
|
|
/// This allows us to search for less types on startup.
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
protected void InitializeModelMappers()
|
2013-06-18 17:22:01 +10:00
|
|
|
|
{
|
2013-07-01 14:23:56 +10:00
|
|
|
|
Mapper.Initialize(configuration =>
|
|
|
|
|
|
{
|
2015-01-21 12:48:08 +11:00
|
|
|
|
//foreach (var m in ApplicationEventsResolver.Current.ApplicationEventHandlers.OfType<IMapperConfiguration>())
|
|
|
|
|
|
foreach (var m in _appStartupEvtContainer.GetAllInstances<IApplicationEventHandler>().OfType<IMapperConfiguration>())
|
2013-07-01 14:23:56 +10:00
|
|
|
|
{
|
2013-07-25 15:31:26 +10:00
|
|
|
|
m.ConfigureMappings(configuration, ApplicationContext);
|
2013-07-01 14:23:56 +10:00
|
|
|
|
}
|
|
|
|
|
|
});
|
2013-06-18 17:22:01 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-01-29 09:45:12 +06:00
|
|
|
|
/// <summary>
|
2015-01-21 12:48:08 +11:00
|
|
|
|
/// Creates the application's IProfiler
|
2013-01-29 09:45:12 +06:00
|
|
|
|
/// </summary>
|
2015-01-21 12:48:08 +11:00
|
|
|
|
protected virtual IProfiler CreateProfiler()
|
2013-01-29 09:45:12 +06:00
|
|
|
|
{
|
2015-01-21 12:48:08 +11:00
|
|
|
|
return new LogProfiler(ProfilingLogger.Logger);
|
2013-01-29 09:45:12 +06:00
|
|
|
|
}
|
|
|
|
|
|
|
2013-05-22 07:48:42 -02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Special method to extend the use of Umbraco by enabling the consumer to overwrite
|
|
|
|
|
|
/// the absolute path to the root of an Umbraco site/solution, which is used for stuff
|
|
|
|
|
|
/// like Umbraco.Core.IO.IOHelper.MapPath etc.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="rootPath">Absolute</param>
|
|
|
|
|
|
protected virtual void InitializeApplicationRootPath(string rootPath)
|
|
|
|
|
|
{
|
2015-01-21 12:48:08 +11:00
|
|
|
|
IO.IOHelper.SetRootDirectory(rootPath);
|
2013-05-22 07:48:42 -02:00
|
|
|
|
}
|
|
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Fires after initialization and calls the callback to allow for customizations to occur &
|
2013-01-29 09:45:12 +06:00
|
|
|
|
/// Ensure that the OnApplicationStarting methods of the IApplicationEvents are called
|
2015-01-07 17:23:24 +11:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="afterStartup"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public virtual IBootManager Startup(Action<ApplicationContext> afterStartup)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_isStarted)
|
|
|
|
|
|
throw new InvalidOperationException("The boot manager has already been initialized");
|
2012-08-07 21:40:34 +06:00
|
|
|
|
|
2013-01-29 09:45:12 +06:00
|
|
|
|
//call OnApplicationStarting of each application events handler
|
2015-01-21 12:48:08 +11:00
|
|
|
|
Parallel.ForEach(_appStartupEvtContainer.GetAllInstances<IApplicationEventHandler>(), x => x.OnApplicationStarting(UmbracoApplication, ApplicationContext));
|
2013-01-29 09:45:12 +06:00
|
|
|
|
|
2013-02-14 23:05:58 +06:00
|
|
|
|
if (afterStartup != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
afterStartup(ApplicationContext.Current);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
_isStarted = true;
|
2012-08-07 21:40:34 +06:00
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
return this;
|
|
|
|
|
|
}
|
2012-08-01 22:06:15 +06:00
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Fires after startup and calls the callback once customizations are locked
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="afterComplete"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public virtual IBootManager Complete(Action<ApplicationContext> afterComplete)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_isComplete)
|
|
|
|
|
|
throw new InvalidOperationException("The boot manager has already been completed");
|
2012-08-01 22:06:15 +06:00
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
FreezeResolution();
|
2012-08-07 21:40:34 +06:00
|
|
|
|
|
2013-01-29 09:45:12 +06:00
|
|
|
|
//call OnApplicationStarting of each application events handler
|
2015-01-21 12:48:08 +11:00
|
|
|
|
Parallel.ForEach(_appStartupEvtContainer.GetAllInstances<IApplicationEventHandler>(), x => x.OnApplicationStarted(UmbracoApplication, ApplicationContext));
|
2013-01-29 09:45:12 +06:00
|
|
|
|
|
2015-01-21 12:48:08 +11:00
|
|
|
|
//end the current scope which was created to intantiate all of the startup handlers
|
|
|
|
|
|
_appStartupEvtContainer.EndCurrentScope();
|
2013-02-14 23:05:58 +06:00
|
|
|
|
|
|
|
|
|
|
if (afterComplete != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
afterComplete(ApplicationContext.Current);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
_isComplete = true;
|
2012-08-07 21:40:34 +06:00
|
|
|
|
|
2013-01-29 09:45:12 +06:00
|
|
|
|
// we're ready to serve content!
|
|
|
|
|
|
ApplicationContext.IsReady = true;
|
|
|
|
|
|
|
2013-11-28 10:51:54 +11:00
|
|
|
|
//stop the timer and log the output
|
|
|
|
|
|
_timer.Dispose();
|
2015-01-07 17:23:24 +11:00
|
|
|
|
return this;
|
|
|
|
|
|
}
|
2012-08-01 22:06:15 +06:00
|
|
|
|
|
2013-03-12 00:21:10 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Freeze resolution to not allow Resolvers to be modified
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
protected virtual void FreezeResolution()
|
|
|
|
|
|
{
|
|
|
|
|
|
Resolution.Freeze();
|
|
|
|
|
|
}
|
2015-01-07 17:23:24 +11:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Create the resolvers
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
protected virtual void InitializeResolvers()
|
|
|
|
|
|
{
|
2015-01-21 12:48:08 +11:00
|
|
|
|
PropertyEditorResolver.Current = new PropertyEditorResolver(ServiceProvider, ProfilingLogger.Logger, () => PluginManager.ResolvePropertyEditors());
|
|
|
|
|
|
ParameterEditorResolver.Current = new ParameterEditorResolver(ServiceProvider, ProfilingLogger.Logger, () => PluginManager.ResolveParameterEditors());
|
2013-09-19 17:34:57 +10:00
|
|
|
|
|
2013-05-23 22:15:52 -10:00
|
|
|
|
//setup the validators resolver with our predefined validators
|
2015-01-16 15:47:44 +11:00
|
|
|
|
ValidatorsResolver.Current = new ValidatorsResolver(
|
2015-01-21 12:48:08 +11:00
|
|
|
|
ServiceProvider, ProfilingLogger.Logger, new[]
|
2013-05-23 22:15:52 -10:00
|
|
|
|
{
|
2013-08-28 13:30:05 +10:00
|
|
|
|
new Lazy<Type>(() => typeof (RequiredManifestValueValidator)),
|
|
|
|
|
|
new Lazy<Type>(() => typeof (RegexValidator)),
|
2013-12-12 18:28:45 +11:00
|
|
|
|
new Lazy<Type>(() => typeof (DelimitedManifestValueValidator)),
|
|
|
|
|
|
new Lazy<Type>(() => typeof (EmailValidator)),
|
|
|
|
|
|
new Lazy<Type>(() => typeof (IntegerValidator)),
|
2013-05-23 22:15:52 -10:00
|
|
|
|
});
|
2013-05-13 20:10:28 -10:00
|
|
|
|
|
2013-02-12 03:46:27 +06:00
|
|
|
|
//by default we'll use the standard configuration based sync
|
2015-01-21 12:48:08 +11:00
|
|
|
|
ServerRegistrarResolver.Current = new ServerRegistrarResolver(Container, typeof(ConfigServerRegistrar));
|
2013-02-12 03:46:27 +06:00
|
|
|
|
|
|
|
|
|
|
//by default (outside of the web) we'll use the default server messenger without
|
|
|
|
|
|
//supplying a username/password, this will automatically disable distributed calls
|
|
|
|
|
|
// .. we'll override this in the WebBootManager
|
2015-01-21 12:48:08 +11:00
|
|
|
|
ServerMessengerResolver.Current = new ServerMessengerResolver(Container, typeof (DefaultServerMessenger));
|
2013-02-11 20:07:23 +06:00
|
|
|
|
|
2013-03-13 01:09:29 +04:00
|
|
|
|
MappingResolver.Current = new MappingResolver(
|
2015-01-21 12:48:08 +11:00
|
|
|
|
ServiceProvider, ProfilingLogger.Logger,
|
2015-01-16 15:47:44 +11:00
|
|
|
|
() => PluginManager.ResolveAssignedMapperTypes());
|
2013-03-13 01:09:29 +04:00
|
|
|
|
|
2015-01-21 12:48:08 +11:00
|
|
|
|
|
2012-12-09 09:01:00 +05:00
|
|
|
|
|
2015-01-13 18:19:52 +11:00
|
|
|
|
//RepositoryResolver.Current = new RepositoryResolver(
|
|
|
|
|
|
// new RepositoryFactory(ApplicationCache));
|
2013-03-09 10:43:34 -01:00
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
CacheRefreshersResolver.Current = new CacheRefreshersResolver(
|
2015-01-21 12:48:08 +11:00
|
|
|
|
ServiceProvider, ProfilingLogger.Logger,
|
2015-01-16 15:47:44 +11:00
|
|
|
|
() => PluginManager.ResolveCacheRefreshers());
|
2015-01-21 12:48:08 +11:00
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
MacroFieldEditorsResolver.Current = new MacroFieldEditorsResolver(
|
2015-01-21 12:48:08 +11:00
|
|
|
|
ServiceProvider, ProfilingLogger.Logger,
|
2015-01-16 15:47:44 +11:00
|
|
|
|
() => PluginManager.ResolveMacroRenderings());
|
2012-08-01 23:03:26 +06:00
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
PackageActionsResolver.Current = new PackageActionsResolver(
|
2015-01-21 12:48:08 +11:00
|
|
|
|
ServiceProvider, ProfilingLogger.Logger,
|
2015-01-16 15:47:44 +11:00
|
|
|
|
() => PluginManager.ResolvePackageActions());
|
2012-08-01 23:30:37 +06:00
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
ActionsResolver.Current = new ActionsResolver(
|
2015-01-21 12:48:08 +11:00
|
|
|
|
ServiceProvider, ProfilingLogger.Logger,
|
2015-01-16 15:47:44 +11:00
|
|
|
|
() => PluginManager.ResolveActions());
|
2012-08-18 11:39:18 +06:00
|
|
|
|
|
2013-02-13 03:29:32 +06:00
|
|
|
|
//the database migration objects
|
|
|
|
|
|
MigrationResolver.Current = new MigrationResolver(
|
2015-01-21 12:48:08 +11:00
|
|
|
|
ServiceProvider, ProfilingLogger.Logger,
|
2015-01-16 15:47:44 +11:00
|
|
|
|
() => PluginManager.ResolveTypes<IMigration>());
|
2013-01-18 12:05:00 -01:00
|
|
|
|
|
2013-02-07 13:30:50 -01:00
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
// need to filter out the ones we dont want!!
|
|
|
|
|
|
PropertyValueConvertersResolver.Current = new PropertyValueConvertersResolver(
|
2015-01-21 12:48:08 +11:00
|
|
|
|
ServiceProvider, ProfilingLogger.Logger,
|
2015-01-16 15:47:44 +11:00
|
|
|
|
PluginManager.ResolveTypes<IPropertyValueConverter>());
|
2013-09-09 15:17:33 +10:00
|
|
|
|
|
2013-12-13 12:06:56 +01:00
|
|
|
|
// use the new DefaultShortStringHelper
|
2015-01-21 12:48:08 +11:00
|
|
|
|
ShortStringHelperResolver.Current = new ShortStringHelperResolver(Container,
|
|
|
|
|
|
factory => new DefaultShortStringHelper(factory.GetInstance<IUmbracoSettingsSection>()).WithDefaultConfig());
|
2013-03-22 17:39:35 -01:00
|
|
|
|
|
2015-01-07 17:23:24 +11:00
|
|
|
|
UrlSegmentProviderResolver.Current = new UrlSegmentProviderResolver(
|
2015-01-21 12:48:08 +11:00
|
|
|
|
Container, ProfilingLogger.Logger,
|
2015-01-07 17:23:24 +11:00
|
|
|
|
typeof(DefaultUrlSegmentProvider));
|
2013-09-13 21:15:40 +02:00
|
|
|
|
|
2014-05-19 13:15:47 +02:00
|
|
|
|
// by default, no factory is activated
|
2015-01-21 12:48:08 +11:00
|
|
|
|
PublishedContentModelFactoryResolver.Current = new PublishedContentModelFactoryResolver(Container);
|
2015-01-07 17:23:24 +11:00
|
|
|
|
}
|
2015-01-21 12:48:08 +11:00
|
|
|
|
|
|
|
|
|
|
///// <summary>
|
|
|
|
|
|
///// An IoC lifetime that will dispose instances at the end of the bootup sequence
|
|
|
|
|
|
///// </summary>
|
|
|
|
|
|
//private class BootManagerLifetime : ILifetime
|
|
|
|
|
|
//{
|
|
|
|
|
|
// public BootManagerLifetime(UmbracoApplicationBase appBase)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// appBase.ApplicationStarted += appBase_ApplicationStarted;
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// void appBase_ApplicationStarted(object sender, EventArgs e)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// throw new NotImplementedException();
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// private object _instance;
|
|
|
|
|
|
|
|
|
|
|
|
// /// <summary>
|
|
|
|
|
|
// /// Returns a service instance according to the specific lifetime characteristics.
|
|
|
|
|
|
// /// </summary>
|
|
|
|
|
|
// /// <param name="createInstance">The function delegate used to create a new service instance.</param>
|
|
|
|
|
|
// /// <param name="scope">The <see cref="Scope"/> of the current service request.</param>
|
|
|
|
|
|
// /// <returns>The requested services instance.</returns>
|
|
|
|
|
|
// public object GetInstance(Func<object> createInstance, Scope scope)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// if (_instance == null)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// _instance = createInstance();
|
|
|
|
|
|
|
|
|
|
|
|
// var disposable = _instance as IDisposable;
|
|
|
|
|
|
// if (disposable != null)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// if (scope == null)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// throw new InvalidOperationException("Attempt to create an disposable object without a current scope.");
|
|
|
|
|
|
// }
|
|
|
|
|
|
// scope.TrackInstance(disposable);
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
// return createInstance;
|
|
|
|
|
|
// }
|
|
|
|
|
|
//}
|
2015-01-07 17:23:24 +11:00
|
|
|
|
}
|
2012-08-01 22:06:15 +06:00
|
|
|
|
}
|