WIP - have added LightInject as a fast and tiny IoC container that is embedded. Have updated all required SingleObjectResolverBase and non lazy ManyObjectResolverBase to use a Container implementation. Have updated the boot managers to use IoC to instantiate all their requirements. This is so much nicer now by using IoC to ctor all of the objects in these resolvers we can get ctor injection OOTB so no more singletons. Need to create resolver to support the lazy resolver with IoC next. Updated IContentFinders, IThumbnailProviders to use ctor injection.
This commit is contained in:
+178
-130
@@ -1,10 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.LightInject;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models.Mapping;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
@@ -12,22 +14,20 @@ using Umbraco.Core.ObjectResolution;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Mappers;
|
||||
using Umbraco.Core.Persistence.Migrations;
|
||||
using Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSix;
|
||||
using Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSixZeroOne;
|
||||
using Umbraco.Core.Persistence.SqlSyntax;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
using Umbraco.Core.Profiling;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.PropertyEditors.ValueConverters;
|
||||
using Umbraco.Core.Publishing;
|
||||
using Umbraco.Core.Macros;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Sync;
|
||||
using Umbraco.Core.Strings;
|
||||
using MigrationsVersionFourNineZero = Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionFourNineZero;
|
||||
|
||||
|
||||
namespace Umbraco.Core
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// A bootstrapper for the Umbraco application which initializes all objects for the Core of the application
|
||||
/// </summary>
|
||||
@@ -36,31 +36,32 @@ namespace Umbraco.Core
|
||||
/// </remarks>
|
||||
public class CoreBootManager : IBootManager
|
||||
{
|
||||
private ProfilingLogger _profilingLogger;
|
||||
internal ServiceContainer Container { get; private set; }
|
||||
private ServiceContainer _appStartupEvtContainer;
|
||||
protected ProfilingLogger ProfilingLogger { get; private set; }
|
||||
private DisposableTimer _timer;
|
||||
protected PluginManager PluginManager { get; private set; }
|
||||
private CacheHelper _cacheHelper;
|
||||
|
||||
private bool _isInitialized = false;
|
||||
private bool _isStarted = false;
|
||||
private bool _isComplete = false;
|
||||
private readonly IServiceProvider _serviceProvider = new ActivatorServiceProvider();
|
||||
private readonly UmbracoApplicationBase _umbracoApplication;
|
||||
protected ApplicationContext ApplicationContext { get; set; }
|
||||
protected CacheHelper ApplicationCache { get; set; }
|
||||
protected PluginManager PluginManager { get; private set; }
|
||||
|
||||
protected ApplicationContext ApplicationContext { get; private set; }
|
||||
|
||||
protected UmbracoApplicationBase UmbracoApplication
|
||||
{
|
||||
get { return _umbracoApplication; }
|
||||
}
|
||||
|
||||
protected IServiceProvider ServiceProvider
|
||||
{
|
||||
get { return _serviceProvider; }
|
||||
}
|
||||
protected IServiceProvider ServiceProvider { get; private set; }
|
||||
|
||||
public CoreBootManager(UmbracoApplicationBase umbracoApplication)
|
||||
{
|
||||
if (umbracoApplication == null) throw new ArgumentNullException("umbracoApplication");
|
||||
_umbracoApplication = umbracoApplication;
|
||||
Container = new ServiceContainer();
|
||||
}
|
||||
|
||||
public virtual IBootManager Initialize()
|
||||
@@ -68,57 +69,47 @@ namespace Umbraco.Core
|
||||
if (_isInitialized)
|
||||
throw new InvalidOperationException("The boot manager has already been initialized");
|
||||
|
||||
InitializeLoggerResolver();
|
||||
InitializeProfilerResolver();
|
||||
//Create logger/profiler, and their resolvers, these are special resolvers that can be resolved before frozen so we can start logging
|
||||
var logger = CreateLogger();
|
||||
LoggerResolver.Current = new LoggerResolver(logger) {CanResolveBeforeFrozen = true};
|
||||
var profiler = CreateProfiler();
|
||||
ProfilerResolver.Current = new ProfilerResolver(profiler) {CanResolveBeforeFrozen = true};
|
||||
ProfilingLogger = new ProfilingLogger(logger, profiler);
|
||||
|
||||
_profilingLogger = new ProfilingLogger(LoggerResolver.Current.Logger, ProfilerResolver.Current.Profiler);
|
||||
_timer = ProfilingLogger.DebugDuration<CoreBootManager>("Umbraco application starting", "Umbraco application startup complete");
|
||||
|
||||
_timer = _profilingLogger.DebugDuration<CoreBootManager>("Umbraco application starting", "Umbraco application startup complete");
|
||||
//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);
|
||||
|
||||
CreateApplicationCache();
|
||||
//build up IoC
|
||||
Container = BuildContainer();
|
||||
|
||||
//create and set the plugin manager (I'd much prefer to not use this singleton anymore but many things are using it unfortunately and
|
||||
// the way that it is setup, there must only ever be one per app so without IoC it would be hard to make this not a singleton)
|
||||
PluginManager = new PluginManager(ServiceProvider, ApplicationCache.RuntimeCache, _profilingLogger);
|
||||
PluginManager.Current = PluginManager;
|
||||
//set the singleton resolved from the core container
|
||||
ApplicationContext.Current = ApplicationContext = Container.GetInstance<ApplicationContext>();
|
||||
|
||||
//Create the legacy prop-eds mapping
|
||||
//TODO: Remove these for v8!
|
||||
LegacyPropertyEditorIdToAliasConverter.CreateMappingsForCoreEditors();
|
||||
LegacyParameterEditorAliasConverter.CreateMappingsForCoreEditors();
|
||||
|
||||
//create database and service contexts for the app context
|
||||
var dbFactory = new DefaultDatabaseFactory(GlobalSettings.UmbracoConnectionName, LoggerResolver.Current.Logger);
|
||||
//TODO: Make this as part of the db ctor!
|
||||
Database.Mapper = new PetaPocoMapper();
|
||||
|
||||
var dbContext = new DatabaseContext(
|
||||
dbFactory,
|
||||
LoggerResolver.Current.Logger,
|
||||
SqlSyntaxProviders.CreateDefault(LoggerResolver.Current.Logger));
|
||||
|
||||
//initialize the DatabaseContext
|
||||
dbContext.Initialize();
|
||||
|
||||
var serviceContext = new ServiceContext(
|
||||
new RepositoryFactory(ApplicationCache, LoggerResolver.Current.Logger, dbContext.SqlSyntax, UmbracoConfig.For.UmbracoSettings()),
|
||||
new PetaPocoUnitOfWorkProvider(dbFactory),
|
||||
new FileUnitOfWorkProvider(),
|
||||
new PublishingStrategy(),
|
||||
ApplicationCache,
|
||||
LoggerResolver.Current.Logger);
|
||||
|
||||
CreateApplicationContext(dbContext, serviceContext);
|
||||
|
||||
InitializeApplicationEventsResolver();
|
||||
//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());
|
||||
|
||||
ConfigureServices(Container);
|
||||
InitializeResolvers();
|
||||
|
||||
|
||||
|
||||
InitializeModelMappers();
|
||||
|
||||
//now we need to call the initialize methods
|
||||
ApplicationEventsResolver.Current.ApplicationEventHandlers
|
||||
.ForEach(x => x.OnApplicationInitialized(UmbracoApplication, ApplicationContext));
|
||||
Parallel.ForEach(_appStartupEvtContainer.GetAllInstances<IApplicationEventHandler>(), x => x.OnApplicationInitialized(UmbracoApplication, ApplicationContext));
|
||||
|
||||
_isInitialized = true;
|
||||
|
||||
@@ -126,28 +117,76 @@ namespace Umbraco.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates and assigns the application context singleton
|
||||
/// Build the core container which contains all core things requird to build an app context
|
||||
/// </summary>
|
||||
/// <param name="dbContext"></param>
|
||||
/// <param name="serviceContext"></param>
|
||||
protected virtual void CreateApplicationContext(DatabaseContext dbContext, ServiceContext serviceContext)
|
||||
private ServiceContainer BuildContainer()
|
||||
{
|
||||
//create the ApplicationContext
|
||||
ApplicationContext = ApplicationContext.Current = new ApplicationContext(dbContext, serviceContext, ApplicationCache, _profilingLogger);
|
||||
var container = new ServiceContainer();
|
||||
container.Register<IUmbracoSettingsSection>(factory => UmbracoConfig.For.UmbracoSettings());
|
||||
container.Register<CacheHelper>(factory => _cacheHelper, new PerContainerLifetime());
|
||||
container.Register<IRuntimeCacheProvider>(factory => _cacheHelper.RuntimeCache, new PerContainerLifetime());
|
||||
container.Register<ILogger>(factory => ProfilingLogger.Logger, new PerContainerLifetime());
|
||||
container.Register<IProfiler>(factory => ProfilingLogger.Profiler, new PerContainerLifetime());
|
||||
container.Register<ProfilingLogger>(factory => ProfilingLogger, 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());
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates and assigns the ApplicationCache based on a new instance of System.Web.Caching.Cache
|
||||
/// Called to customize the IoC container
|
||||
/// </summary>
|
||||
protected virtual void CreateApplicationCache()
|
||||
/// <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
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
/// <returns></returns>
|
||||
private DatabaseContext GetDbContext(IServiceFactory container)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the ApplicationCache based on a new instance of System.Web.Caching.Cache
|
||||
/// </summary>
|
||||
protected virtual CacheHelper CreateApplicationCache()
|
||||
{
|
||||
var cacheHelper = new CacheHelper(
|
||||
new ObjectCacheRuntimeCacheProvider(),
|
||||
new StaticCacheProvider(),
|
||||
new ObjectCacheRuntimeCacheProvider(),
|
||||
new StaticCacheProvider(),
|
||||
//we have no request based cache when not running in web-based context
|
||||
new NullCacheProvider());
|
||||
new NullCacheProvider());
|
||||
|
||||
ApplicationCache = cacheHelper;
|
||||
return cacheHelper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -161,7 +200,8 @@ namespace Umbraco.Core
|
||||
{
|
||||
Mapper.Initialize(configuration =>
|
||||
{
|
||||
foreach (var m in ApplicationEventsResolver.Current.ApplicationEventHandlers.OfType<IMapperConfiguration>())
|
||||
//foreach (var m in ApplicationEventsResolver.Current.ApplicationEventHandlers.OfType<IMapperConfiguration>())
|
||||
foreach (var m in _appStartupEvtContainer.GetAllInstances<IApplicationEventHandler>().OfType<IMapperConfiguration>())
|
||||
{
|
||||
m.ConfigureMappings(configuration, ApplicationContext);
|
||||
}
|
||||
@@ -169,50 +209,19 @@ namespace Umbraco.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Special method to initialize the LoggerResolver
|
||||
/// Creates the application's ILogger
|
||||
/// </summary>
|
||||
protected virtual void InitializeLoggerResolver()
|
||||
protected virtual ILogger CreateLogger()
|
||||
{
|
||||
LoggerResolver.Current = new LoggerResolver(Logger.CreateWithDefaultLog4NetConfiguration())
|
||||
{
|
||||
//This is another special resolver that needs to be resolvable before resolution is frozen
|
||||
//since it is used for profiling the application startup
|
||||
CanResolveBeforeFrozen = true
|
||||
};
|
||||
return Logger.CreateWithDefaultLog4NetConfiguration();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Special method to initialize the ProfilerResolver
|
||||
/// Creates the application's IProfiler
|
||||
/// </summary>
|
||||
protected virtual void InitializeProfilerResolver()
|
||||
protected virtual IProfiler CreateProfiler()
|
||||
{
|
||||
//By default we'll initialize the Log profiler (in the web project, we'll override with the web profiler)
|
||||
ProfilerResolver.Current = new ProfilerResolver(new LogProfiler(LoggerResolver.Current.Logger))
|
||||
{
|
||||
//This is another special resolver that needs to be resolvable before resolution is frozen
|
||||
//since it is used for profiling the application startup
|
||||
CanResolveBeforeFrozen = true
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Special method to initialize the ApplicationEventsResolver and any modifications required for it such
|
||||
/// as adding custom types to the resolver.
|
||||
/// </summary>
|
||||
protected virtual void InitializeApplicationEventsResolver()
|
||||
{
|
||||
//find and initialize the application startup handlers, we need to initialize this resolver here because
|
||||
//it is a special resolver where they need to be instantiated first before any other resolvers in order to bind to
|
||||
//events and to call their events during bootup.
|
||||
//ApplicationStartupHandler.RegisterHandlers();
|
||||
//... and set the special flag to let us resolve before frozen resolution
|
||||
ApplicationEventsResolver.Current = new ApplicationEventsResolver(
|
||||
ServiceProvider,
|
||||
LoggerResolver.Current.Logger,
|
||||
PluginManager.ResolveApplicationStartupHandlers())
|
||||
{
|
||||
CanResolveBeforeFrozen = true
|
||||
};
|
||||
return new LogProfiler(ProfilingLogger.Logger);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -223,7 +232,7 @@ namespace Umbraco.Core
|
||||
/// <param name="rootPath">Absolute</param>
|
||||
protected virtual void InitializeApplicationRootPath(string rootPath)
|
||||
{
|
||||
Umbraco.Core.IO.IOHelper.SetRootDirectory(rootPath);
|
||||
IO.IOHelper.SetRootDirectory(rootPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -238,8 +247,7 @@ namespace Umbraco.Core
|
||||
throw new InvalidOperationException("The boot manager has already been initialized");
|
||||
|
||||
//call OnApplicationStarting of each application events handler
|
||||
ApplicationEventsResolver.Current.ApplicationEventHandlers
|
||||
.ForEach(x => x.OnApplicationStarting(UmbracoApplication, ApplicationContext));
|
||||
Parallel.ForEach(_appStartupEvtContainer.GetAllInstances<IApplicationEventHandler>(), x => x.OnApplicationStarting(UmbracoApplication, ApplicationContext));
|
||||
|
||||
if (afterStartup != null)
|
||||
{
|
||||
@@ -264,11 +272,10 @@ namespace Umbraco.Core
|
||||
FreezeResolution();
|
||||
|
||||
//call OnApplicationStarting of each application events handler
|
||||
ApplicationEventsResolver.Current.ApplicationEventHandlers
|
||||
.ForEach(x => x.OnApplicationStarted(UmbracoApplication, ApplicationContext));
|
||||
Parallel.ForEach(_appStartupEvtContainer.GetAllInstances<IApplicationEventHandler>(), x => x.OnApplicationStarted(UmbracoApplication, ApplicationContext));
|
||||
|
||||
//Now, startup all of our legacy startup handler
|
||||
ApplicationEventsResolver.Current.InstantiateLegacyStartupHandlers();
|
||||
//end the current scope which was created to intantiate all of the startup handlers
|
||||
_appStartupEvtContainer.EndCurrentScope();
|
||||
|
||||
if (afterComplete != null)
|
||||
{
|
||||
@@ -298,12 +305,12 @@ namespace Umbraco.Core
|
||||
/// </summary>
|
||||
protected virtual void InitializeResolvers()
|
||||
{
|
||||
PropertyEditorResolver.Current = new PropertyEditorResolver(ServiceProvider, LoggerResolver.Current.Logger, () => PluginManager.ResolvePropertyEditors());
|
||||
ParameterEditorResolver.Current = new ParameterEditorResolver(ServiceProvider, LoggerResolver.Current.Logger, () => PluginManager.ResolveParameterEditors());
|
||||
PropertyEditorResolver.Current = new PropertyEditorResolver(ServiceProvider, ProfilingLogger.Logger, () => PluginManager.ResolvePropertyEditors());
|
||||
ParameterEditorResolver.Current = new ParameterEditorResolver(ServiceProvider, ProfilingLogger.Logger, () => PluginManager.ResolveParameterEditors());
|
||||
|
||||
//setup the validators resolver with our predefined validators
|
||||
ValidatorsResolver.Current = new ValidatorsResolver(
|
||||
ServiceProvider, LoggerResolver.Current.Logger, new[]
|
||||
ServiceProvider, ProfilingLogger.Logger, new[]
|
||||
{
|
||||
new Lazy<Type>(() => typeof (RequiredManifestValueValidator)),
|
||||
new Lazy<Type>(() => typeof (RegexValidator)),
|
||||
@@ -313,62 +320,103 @@ namespace Umbraco.Core
|
||||
});
|
||||
|
||||
//by default we'll use the standard configuration based sync
|
||||
ServerRegistrarResolver.Current = new ServerRegistrarResolver(
|
||||
new ConfigServerRegistrar());
|
||||
ServerRegistrarResolver.Current = new ServerRegistrarResolver(Container, typeof(ConfigServerRegistrar));
|
||||
|
||||
//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
|
||||
ServerMessengerResolver.Current = new ServerMessengerResolver(
|
||||
new DefaultServerMessenger());
|
||||
ServerMessengerResolver.Current = new ServerMessengerResolver(Container, typeof (DefaultServerMessenger));
|
||||
|
||||
MappingResolver.Current = new MappingResolver(
|
||||
ServiceProvider, LoggerResolver.Current.Logger,
|
||||
ServiceProvider, ProfilingLogger.Logger,
|
||||
() => PluginManager.ResolveAssignedMapperTypes());
|
||||
|
||||
|
||||
|
||||
|
||||
//RepositoryResolver.Current = new RepositoryResolver(
|
||||
// new RepositoryFactory(ApplicationCache));
|
||||
|
||||
CacheRefreshersResolver.Current = new CacheRefreshersResolver(
|
||||
ServiceProvider, LoggerResolver.Current.Logger,
|
||||
ServiceProvider, ProfilingLogger.Logger,
|
||||
() => PluginManager.ResolveCacheRefreshers());
|
||||
|
||||
|
||||
MacroFieldEditorsResolver.Current = new MacroFieldEditorsResolver(
|
||||
ServiceProvider, LoggerResolver.Current.Logger,
|
||||
ServiceProvider, ProfilingLogger.Logger,
|
||||
() => PluginManager.ResolveMacroRenderings());
|
||||
|
||||
PackageActionsResolver.Current = new PackageActionsResolver(
|
||||
ServiceProvider, LoggerResolver.Current.Logger,
|
||||
ServiceProvider, ProfilingLogger.Logger,
|
||||
() => PluginManager.ResolvePackageActions());
|
||||
|
||||
ActionsResolver.Current = new ActionsResolver(
|
||||
ServiceProvider, LoggerResolver.Current.Logger,
|
||||
ServiceProvider, ProfilingLogger.Logger,
|
||||
() => PluginManager.ResolveActions());
|
||||
|
||||
//the database migration objects
|
||||
MigrationResolver.Current = new MigrationResolver(
|
||||
ServiceProvider, LoggerResolver.Current.Logger,
|
||||
ServiceProvider, ProfilingLogger.Logger,
|
||||
() => PluginManager.ResolveTypes<IMigration>());
|
||||
|
||||
|
||||
// need to filter out the ones we dont want!!
|
||||
PropertyValueConvertersResolver.Current = new PropertyValueConvertersResolver(
|
||||
ServiceProvider, LoggerResolver.Current.Logger,
|
||||
ServiceProvider, ProfilingLogger.Logger,
|
||||
PluginManager.ResolveTypes<IPropertyValueConverter>());
|
||||
|
||||
// use the new DefaultShortStringHelper
|
||||
ShortStringHelperResolver.Current = new ShortStringHelperResolver(
|
||||
//new LegacyShortStringHelper());
|
||||
new DefaultShortStringHelper().WithDefaultConfig());
|
||||
ShortStringHelperResolver.Current = new ShortStringHelperResolver(Container,
|
||||
factory => new DefaultShortStringHelper(factory.GetInstance<IUmbracoSettingsSection>()).WithDefaultConfig());
|
||||
|
||||
UrlSegmentProviderResolver.Current = new UrlSegmentProviderResolver(
|
||||
ServiceProvider, LoggerResolver.Current.Logger,
|
||||
Container, ProfilingLogger.Logger,
|
||||
typeof(DefaultUrlSegmentProvider));
|
||||
|
||||
// by default, no factory is activated
|
||||
PublishedContentModelFactoryResolver.Current = new PublishedContentModelFactoryResolver();
|
||||
PublishedContentModelFactoryResolver.Current = new PublishedContentModelFactoryResolver(Container);
|
||||
}
|
||||
|
||||
///// <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;
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
using Umbraco.Core.LightInject;
|
||||
using Umbraco.Core.ObjectResolution;
|
||||
|
||||
namespace Umbraco.Core.Dictionary
|
||||
@@ -5,14 +8,34 @@ namespace Umbraco.Core.Dictionary
|
||||
/// <summary>
|
||||
/// Resolves the current CultureDictionaryFactory
|
||||
/// </summary>
|
||||
public sealed class CultureDictionaryFactoryResolver : SingleObjectResolverBase<CultureDictionaryFactoryResolver, ICultureDictionaryFactory>
|
||||
public sealed class CultureDictionaryFactoryResolver : ContainerSingleObjectResolver<CultureDictionaryFactoryResolver, ICultureDictionaryFactory>
|
||||
{
|
||||
internal CultureDictionaryFactoryResolver(ICultureDictionaryFactory factory)
|
||||
/// <summary>
|
||||
/// Initializes the resolver to use IoC
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
/// <param name="implementationType"></param>
|
||||
internal CultureDictionaryFactoryResolver(IServiceContainer container, Type implementationType)
|
||||
: base(container, implementationType)
|
||||
{
|
||||
}
|
||||
|
||||
internal CultureDictionaryFactoryResolver(ICultureDictionaryFactory factory)
|
||||
: base(factory)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// Initializes the resolver to use IoC
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
/// <param name="implementationType"></param>
|
||||
internal CultureDictionaryFactoryResolver(IServiceContainer container, Expression<Func<IServiceFactory, ICultureDictionaryFactory>> implementationType)
|
||||
: base(container, implementationType)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Can be used by developers at runtime to set their ICultureDictionaryFactory at app startup
|
||||
/// </summary>
|
||||
/// <param name="factory"></param>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -2,6 +2,12 @@ using Umbraco.Core.ObjectResolution;
|
||||
|
||||
namespace Umbraco.Core.Logging
|
||||
{
|
||||
/// <summary>
|
||||
/// The logger resolver
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// NOTE: This is a 'special' resolver in that it gets initialized before most other things, it cannot use IoC so it cannot implement ContainerObjectResolverBase
|
||||
/// </remarks>
|
||||
public sealed class LoggerResolver : SingleObjectResolverBase<LoggerResolver, ILogger>
|
||||
{
|
||||
public LoggerResolver(ILogger logger)
|
||||
|
||||
@@ -1,12 +1,24 @@
|
||||
using Umbraco.Core.ObjectResolution;
|
||||
using System;
|
||||
using Umbraco.Core.LightInject;
|
||||
using Umbraco.Core.ObjectResolution;
|
||||
|
||||
namespace Umbraco.Core.Models.PublishedContent
|
||||
{
|
||||
/// <summary>
|
||||
/// Resolves the IPublishedContentModelFactory object.
|
||||
/// </summary>
|
||||
public class PublishedContentModelFactoryResolver : SingleObjectResolverBase<PublishedContentModelFactoryResolver, IPublishedContentModelFactory>
|
||||
public class PublishedContentModelFactoryResolver : ContainerSingleObjectResolver<PublishedContentModelFactoryResolver, IPublishedContentModelFactory>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes the resolver to use IoC
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
/// <param name="implementationType"></param>
|
||||
internal PublishedContentModelFactoryResolver(IServiceContainer container, Type implementationType)
|
||||
: base(container, implementationType)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PublishedContentModelFactoryResolver"/>.
|
||||
/// </summary>
|
||||
@@ -24,6 +36,15 @@ namespace Umbraco.Core.Models.PublishedContent
|
||||
: base(factory)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the resolver to use IoC, when using this contructor the type must be set manually
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
internal PublishedContentModelFactoryResolver(IServiceContainer container)
|
||||
: base(container)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the factory.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,151 +1,172 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Umbraco.Core.Logging;
|
||||
using umbraco.interfaces;
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
//using System.Threading;
|
||||
//using Umbraco.Core.LightInject;
|
||||
//using Umbraco.Core.Logging;
|
||||
//using Umbraco.Core.Services;
|
||||
//using umbraco.interfaces;
|
||||
|
||||
namespace Umbraco.Core.ObjectResolution
|
||||
{
|
||||
/// <summary>
|
||||
/// A resolver to return all IApplicationEvents objects
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is disposable because after the app has started it should be disposed to release any memory being occupied by instances.
|
||||
/// </remarks>
|
||||
internal sealed class ApplicationEventsResolver : ManyObjectsResolverBase<ApplicationEventsResolver, IApplicationEventHandler>, IDisposable
|
||||
{
|
||||
//namespace Umbraco.Core.ObjectResolution
|
||||
//{
|
||||
// /// <summary>
|
||||
// /// A resolver to return all IApplicationEvents objects
|
||||
// /// </summary>
|
||||
// /// <remarks>
|
||||
// /// This is disposable because after the app has started it should be disposed to release any memory being occupied by instances.
|
||||
// /// </remarks>
|
||||
// internal sealed class ApplicationEventsResolver : ManyObjectsResolverBase<ApplicationEventsResolver, IApplicationEventHandler>, IDisposable
|
||||
// {
|
||||
// private IServiceContainer _container;
|
||||
// private readonly LegacyStartupHandlerResolver _legacyResolver;
|
||||
|
||||
private readonly LegacyStartupHandlerResolver _legacyResolver;
|
||||
// public ApplicationEventsResolver(IServiceContainer container, IEnumerable<Type> applicationEventHandlers)
|
||||
// : base(container.GetInstance<IServiceProvider>(), container.GetInstance<ILogger>(), applicationEventHandlers)
|
||||
// {
|
||||
// //create the legacy resolver and only include the legacy types
|
||||
// _legacyResolver = new LegacyStartupHandlerResolver(
|
||||
// container,
|
||||
// applicationEventHandlers.Where(x => TypeHelper.IsTypeAssignableFrom<IApplicationEventHandler>(x) == false));
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="applicationEventHandlers"></param>
|
||||
/// <param name="serviceProvider"></param>
|
||||
internal ApplicationEventsResolver(IServiceProvider serviceProvider, ILogger logger, IEnumerable<Type> applicationEventHandlers)
|
||||
: base(serviceProvider, logger, applicationEventHandlers)
|
||||
{
|
||||
//create the legacy resolver and only include the legacy types
|
||||
_legacyResolver = new LegacyStartupHandlerResolver(
|
||||
applicationEventHandlers.Where(x => !TypeHelper.IsTypeAssignableFrom<IApplicationEventHandler>(x)));
|
||||
}
|
||||
// ///// <summary>
|
||||
// ///// Constructor
|
||||
// ///// </summary>
|
||||
// ///// <param name="logger"></param>
|
||||
// ///// <param name="applicationEventHandlers"></param>
|
||||
// ///// <param name="parentContainer"></param>
|
||||
// ///// <param name="serviceProvider"></param>
|
||||
// //internal ApplicationEventsResolver(IServiceContainer parentContainer, IServiceProvider serviceProvider, ILogger logger, IEnumerable<Type> applicationEventHandlers)
|
||||
// // : base(serviceProvider, logger, applicationEventHandlers)
|
||||
// //{
|
||||
// // //create the legacy resolver and only include the legacy types
|
||||
// // _legacyResolver = new LegacyStartupHandlerResolver(
|
||||
// // applicationEventHandlers.Where(x => !TypeHelper.IsTypeAssignableFrom<IApplicationEventHandler>(x)));
|
||||
// //}
|
||||
|
||||
/// <summary>
|
||||
/// Override in order to only return types of IApplicationEventHandler and above,
|
||||
/// do not include the legacy types of IApplicationStartupHandler
|
||||
/// </summary>
|
||||
protected override IEnumerable<Type> InstanceTypes
|
||||
{
|
||||
get { return base.InstanceTypes.Where(TypeHelper.IsTypeAssignableFrom<IApplicationEventHandler>); }
|
||||
}
|
||||
// /// <summary>
|
||||
// /// Override in order to only return types of IApplicationEventHandler and above,
|
||||
// /// do not include the legacy types of IApplicationStartupHandler
|
||||
// /// </summary>
|
||||
// protected override IEnumerable<Type> InstanceTypes
|
||||
// {
|
||||
// get { return base.InstanceTypes.Where(TypeHelper.IsTypeAssignableFrom<IApplicationEventHandler>); }
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IApplicationEventHandler"/> implementations.
|
||||
/// </summary>
|
||||
public IEnumerable<IApplicationEventHandler> ApplicationEventHandlers
|
||||
{
|
||||
get { return Values; }
|
||||
}
|
||||
// /// <summary>
|
||||
// /// Gets the <see cref="IApplicationEventHandler"/> implementations.
|
||||
// /// </summary>
|
||||
// public IEnumerable<IApplicationEventHandler> ApplicationEventHandlers
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
|
||||
// //return Values;
|
||||
// }
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// Create instances of all of the legacy startup handlers
|
||||
/// </summary>
|
||||
public void InstantiateLegacyStartupHandlers()
|
||||
{
|
||||
//this will instantiate them all
|
||||
var handlers = _legacyResolver.LegacyStartupHandlers;
|
||||
}
|
||||
// /// <summary>
|
||||
// /// Create instances of all of the legacy startup handlers
|
||||
// /// </summary>
|
||||
// public void InstantiateLegacyStartupHandlers()
|
||||
// {
|
||||
// //this will instantiate them all
|
||||
// var handlers = _legacyResolver.LegacyStartupHandlers;
|
||||
// }
|
||||
|
||||
protected override bool SupportsClear
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
// protected override bool SupportsClear
|
||||
// {
|
||||
// get { return false; }
|
||||
// }
|
||||
|
||||
protected override bool SupportsInsert
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
// protected override bool SupportsInsert
|
||||
// {
|
||||
// get { return false; }
|
||||
// }
|
||||
|
||||
private class LegacyStartupHandlerResolver : ManyObjectsResolverBase<ApplicationEventsResolver, IApplicationStartupHandler>, IDisposable
|
||||
{
|
||||
internal LegacyStartupHandlerResolver(IEnumerable<Type> legacyStartupHandlers)
|
||||
: base(legacyStartupHandlers)
|
||||
{
|
||||
// private class LegacyStartupHandlerResolver : ManyObjectsResolverBase<ApplicationEventsResolver, IApplicationStartupHandler>, IDisposable
|
||||
// {
|
||||
// internal LegacyStartupHandlerResolver(IServiceContainer container, IEnumerable<Type> applicationEventHandlers)
|
||||
// : base(container.GetInstance<IServiceProvider>(), container.GetInstance<ILogger>(), applicationEventHandlers)
|
||||
// {
|
||||
// }
|
||||
|
||||
}
|
||||
// //internal LegacyStartupHandlerResolver(IEnumerable<Type> legacyStartupHandlers)
|
||||
// // : base(legacyStartupHandlers)
|
||||
// //{
|
||||
|
||||
public IEnumerable<IApplicationStartupHandler> LegacyStartupHandlers
|
||||
{
|
||||
get { return Values; }
|
||||
}
|
||||
// //}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
ResetCollections();
|
||||
}
|
||||
}
|
||||
// public IEnumerable<IApplicationStartupHandler> LegacyStartupHandlers
|
||||
// {
|
||||
// get { return Values; }
|
||||
// }
|
||||
|
||||
private bool _disposed;
|
||||
private readonly ReaderWriterLockSlim _disposalLocker = new ReaderWriterLockSlim();
|
||||
// public void Dispose()
|
||||
// {
|
||||
// ResetCollections();
|
||||
// }
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this instance is disposed.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <c>true</c> if this instance is disposed; otherwise, <c>false</c>.
|
||||
/// </value>
|
||||
public bool IsDisposed
|
||||
{
|
||||
get { return _disposed; }
|
||||
}
|
||||
// private bool _disposed;
|
||||
// private readonly ReaderWriterLockSlim _disposalLocker = new ReaderWriterLockSlim();
|
||||
|
||||
/// <summary>
|
||||
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
|
||||
/// </summary>
|
||||
/// <filterpriority>2</filterpriority>
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
// /// <summary>
|
||||
// /// Gets a value indicating whether this instance is disposed.
|
||||
// /// </summary>
|
||||
// /// <value>
|
||||
// /// <c>true</c> if this instance is disposed; otherwise, <c>false</c>.
|
||||
// /// </value>
|
||||
// public bool IsDisposed
|
||||
// {
|
||||
// get { return _disposed; }
|
||||
// }
|
||||
|
||||
// Use SupressFinalize in case a subclass of this type implements a finalizer.
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
// /// <summary>
|
||||
// /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
|
||||
// /// </summary>
|
||||
// /// <filterpriority>2</filterpriority>
|
||||
// public void Dispose()
|
||||
// {
|
||||
// Dispose(true);
|
||||
|
||||
~ApplicationEventsResolver()
|
||||
{
|
||||
// Run dispose but let the class know it was due to the finalizer running.
|
||||
Dispose(false);
|
||||
}
|
||||
// // Use SupressFinalize in case a subclass of this type implements a finalizer.
|
||||
// GC.SuppressFinalize(this);
|
||||
// }
|
||||
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
// Only operate if we haven't already disposed
|
||||
if (IsDisposed || disposing == false) return;
|
||||
// ~ApplicationEventsResolver()
|
||||
// {
|
||||
// // Run dispose but let the class know it was due to the finalizer running.
|
||||
// Dispose(false);
|
||||
// }
|
||||
|
||||
using (new WriteLock(_disposalLocker))
|
||||
{
|
||||
// Check again now we're inside the lock
|
||||
if (IsDisposed) return;
|
||||
// private void Dispose(bool disposing)
|
||||
// {
|
||||
// // Only operate if we haven't already disposed
|
||||
// if (IsDisposed || disposing == false) return;
|
||||
|
||||
// Call to actually release resources. This method is only
|
||||
// kept separate so that the entire disposal logic can be used as a VS snippet
|
||||
DisposeResources();
|
||||
// using (new WriteLock(_disposalLocker))
|
||||
// {
|
||||
// // Check again now we're inside the lock
|
||||
// if (IsDisposed) return;
|
||||
|
||||
// Indicate that the instance has been disposed.
|
||||
_disposed = true;
|
||||
}
|
||||
}
|
||||
// // Call to actually release resources. This method is only
|
||||
// // kept separate so that the entire disposal logic can be used as a VS snippet
|
||||
// DisposeResources();
|
||||
|
||||
/// <summary>
|
||||
/// Clear out all of the instances, we don't want them hanging around and cluttering up memory
|
||||
/// </summary>
|
||||
private void DisposeResources()
|
||||
{
|
||||
_legacyResolver.Dispose();
|
||||
ResetCollections();
|
||||
}
|
||||
// // Indicate that the instance has been disposed.
|
||||
// _disposed = true;
|
||||
// }
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// Clear out all of the instances, we don't want them hanging around and cluttering up memory
|
||||
// /// </summary>
|
||||
// private void DisposeResources()
|
||||
// {
|
||||
// _legacyResolver.Dispose();
|
||||
// ResetCollections();
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
// }
|
||||
//}
|
||||
@@ -0,0 +1,109 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using Umbraco.Core.LightInject;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Security;
|
||||
|
||||
namespace Umbraco.Core.ObjectResolution
|
||||
{
|
||||
/// <summary>
|
||||
/// A many objects resolver that uses IoC
|
||||
/// </summary>
|
||||
/// <typeparam name="TResolver"></typeparam>
|
||||
/// <typeparam name="TResolved"></typeparam>
|
||||
public abstract class ContainerManyObjectsResolver<TResolver, TResolved> : ManyObjectsResolverBase<TResolver, TResolved>
|
||||
where TResolved : class
|
||||
where TResolver : ResolverBase
|
||||
{
|
||||
private readonly IServiceContainer _container;
|
||||
|
||||
#region Constructors used for test - ONLY so that a container is not required and will just revert to using the normal ManyObjectsResolverBase
|
||||
[Obsolete("Used for tests only - should remove")]
|
||||
internal ContainerManyObjectsResolver(ILogger logger, IEnumerable<Type> types, ObjectLifetimeScope scope = ObjectLifetimeScope.Application)
|
||||
: base(logger, types, scope)
|
||||
{
|
||||
}
|
||||
[Obsolete("Used for tests only - should remove")]
|
||||
internal ContainerManyObjectsResolver(IServiceProvider serviceProvider, ILogger logger, ObjectLifetimeScope scope = ObjectLifetimeScope.Application)
|
||||
: base(serviceProvider, logger, scope)
|
||||
{
|
||||
}
|
||||
[Obsolete("Used for tests only - should remove")]
|
||||
internal ContainerManyObjectsResolver(IServiceProvider serviceProvider, ILogger logger, HttpContextBase httpContext)
|
||||
: base(serviceProvider, logger, httpContext)
|
||||
{
|
||||
}
|
||||
[Obsolete("Used for tests only - should remove")]
|
||||
internal ContainerManyObjectsResolver(IServiceProvider serviceProvider, ILogger logger, IEnumerable<Type> value, ObjectLifetimeScope scope = ObjectLifetimeScope.Application)
|
||||
: base(serviceProvider, logger, value, scope)
|
||||
{
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for use with IoC
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="types"></param>
|
||||
/// <param name="scope"></param>
|
||||
internal ContainerManyObjectsResolver(IServiceContainer container, ILogger logger, IEnumerable<Type> types, ObjectLifetimeScope scope = ObjectLifetimeScope.Application)
|
||||
: base(logger, types, scope)
|
||||
{
|
||||
_container = container;
|
||||
|
||||
|
||||
Resolution.Frozen += Resolution_Frozen;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// When resolution is frozen add all the types to the container
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
void Resolution_Frozen(object sender, EventArgs e)
|
||||
{
|
||||
foreach (var type in InstanceTypes)
|
||||
{
|
||||
_container.Register(type, GetLifetime(LifetimeScope));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert the ObjectLifetimeScope to ILifetime
|
||||
/// </summary>
|
||||
/// <param name="scope"></param>
|
||||
/// <returns></returns>
|
||||
private static ILifetime GetLifetime(ObjectLifetimeScope scope)
|
||||
{
|
||||
switch (scope)
|
||||
{
|
||||
case ObjectLifetimeScope.HttpRequest:
|
||||
return new PerRequestLifeTime();
|
||||
case ObjectLifetimeScope.Application:
|
||||
return new PerContainerLifetime();
|
||||
case ObjectLifetimeScope.Transient:
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the instances from IoC
|
||||
/// </summary>
|
||||
/// <returns>A list of objects of type <typeparamref name="TResolved"/>.</returns>
|
||||
protected override IEnumerable<TResolved> CreateValues(ObjectLifetimeScope scope)
|
||||
{
|
||||
//NOTE: we ignore scope because objects are registered under this scope and not build based on the scope.
|
||||
|
||||
return _container.GetAllInstances<TResolved>();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
using Umbraco.Core.LightInject;
|
||||
|
||||
namespace Umbraco.Core.ObjectResolution
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// A single object resolver that can be configured to use IoC to instantiate and wire up the object
|
||||
/// </summary>
|
||||
/// <typeparam name="TResolver"></typeparam>
|
||||
/// <typeparam name="TResolved"></typeparam>
|
||||
public abstract class ContainerSingleObjectResolver<TResolver, TResolved> : SingleObjectResolverBase<TResolver, TResolved>
|
||||
where TResolved : class
|
||||
where TResolver : ResolverBase
|
||||
{
|
||||
private readonly IServiceContainer _container;
|
||||
|
||||
|
||||
#region Constructors used for test - ONLY so that a container is not required and will just revert to using the normal SingleObjectResolverBase
|
||||
|
||||
[Obsolete("Used for tests only - should remove")]
|
||||
internal ContainerSingleObjectResolver()
|
||||
{
|
||||
}
|
||||
|
||||
[Obsolete("Used for tests only - should remove")]
|
||||
internal ContainerSingleObjectResolver(TResolved value)
|
||||
: base(value)
|
||||
{
|
||||
}
|
||||
|
||||
[Obsolete("Used for tests only - should remove")]
|
||||
internal ContainerSingleObjectResolver(bool canBeNull)
|
||||
: base(canBeNull)
|
||||
{
|
||||
}
|
||||
|
||||
[Obsolete("Used for tests only - should remove")]
|
||||
internal ContainerSingleObjectResolver(TResolved value, bool canBeNull)
|
||||
: base(value, canBeNull)
|
||||
{
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the resolver to use IoC
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
/// <param name="implementationType"></param>
|
||||
internal ContainerSingleObjectResolver(IServiceContainer container, Type implementationType)
|
||||
{
|
||||
if (container == null) throw new ArgumentNullException("container");
|
||||
if (implementationType == null) throw new ArgumentNullException("implementationType");
|
||||
_container = container;
|
||||
_container.Register(typeof(TResolved), implementationType, new PerContainerLifetime());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the resolver to use IoC, when using this contructor the type must be set manually
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
internal ContainerSingleObjectResolver(IServiceContainer container)
|
||||
{
|
||||
if (container == null) throw new ArgumentNullException("container");
|
||||
_container = container;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the resolver to use IoC
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
/// <param name="implementationType"></param>
|
||||
internal ContainerSingleObjectResolver(IServiceContainer container, Expression<Func<IServiceFactory, TResolved>> implementationType)
|
||||
{
|
||||
_container = container;
|
||||
_container.Register<TResolved>(implementationType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the resolved object instance.
|
||||
/// </summary>
|
||||
/// <remarks></remarks>
|
||||
/// <exception cref="ArgumentNullException">value is set to null, but cannot be null (<c>CanBeNull</c> is <c>false</c>).</exception>
|
||||
/// <exception cref="InvalidOperationException">value is read and is null, but cannot be null (<c>CanBeNull</c> is <c>false</c>),
|
||||
/// or value is set (read) and resolution is (not) frozen.</exception>
|
||||
protected override TResolved Value
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_container == null) return base.Value;
|
||||
return _container.GetInstance<TResolved>();
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_container != null)
|
||||
{
|
||||
_container.Override(
|
||||
sr => sr.ServiceType == typeof (TResolved),
|
||||
(factory, registration) =>
|
||||
{
|
||||
registration.Value = value;
|
||||
registration.Lifetime = new PerContainerLifetime();
|
||||
return registration;
|
||||
});
|
||||
}
|
||||
base.Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the resolved object instance is null.
|
||||
/// </summary>
|
||||
public override bool HasValue
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_container == null) return base.HasValue;
|
||||
return (_container.TryGetInstance<TResolved>() == null) == false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,74 +39,30 @@ namespace Umbraco.Core.ObjectResolution
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("Use ctor specifying IServiceProvider instead")]
|
||||
protected LazyManyObjectsResolverBase(ObjectLifetimeScope scope = ObjectLifetimeScope.Application)
|
||||
: base(scope)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("Use ctor specifying IServiceProvider instead")]
|
||||
protected LazyManyObjectsResolverBase(HttpContextBase httpContext)
|
||||
: base(httpContext)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
|
||||
protected LazyManyObjectsResolverBase(IServiceProvider serviceProvider, ILogger logger, IEnumerable<Lazy<Type>> lazyTypeList, ObjectLifetimeScope scope = ObjectLifetimeScope.Application)
|
||||
: this(serviceProvider, logger, scope)
|
||||
{
|
||||
AddTypes(lazyTypeList);
|
||||
}
|
||||
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("Use ctor specifying IServiceProvider instead")]
|
||||
protected LazyManyObjectsResolverBase(IEnumerable<Lazy<Type>> lazyTypeList, ObjectLifetimeScope scope = ObjectLifetimeScope.Application)
|
||||
: this(new ActivatorServiceProvider(), LoggerResolver.Current.Logger, lazyTypeList, scope)
|
||||
{
|
||||
}
|
||||
|
||||
protected LazyManyObjectsResolverBase(IServiceProvider serviceProvider, ILogger logger, Func<IEnumerable<Type>> typeListProducerList, ObjectLifetimeScope scope = ObjectLifetimeScope.Application)
|
||||
: this(serviceProvider, logger, scope)
|
||||
{
|
||||
_typeListProducerList.Add(typeListProducerList);
|
||||
}
|
||||
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("Use ctor specifying IServiceProvider instead")]
|
||||
protected LazyManyObjectsResolverBase(Func<IEnumerable<Type>> typeListProducerList, ObjectLifetimeScope scope = ObjectLifetimeScope.Application)
|
||||
: this(new ActivatorServiceProvider(), LoggerResolver.Current.Logger, typeListProducerList, scope)
|
||||
{
|
||||
}
|
||||
|
||||
protected LazyManyObjectsResolverBase(IServiceProvider serviceProvider, ILogger logger, HttpContextBase httpContext, IEnumerable<Lazy<Type>> lazyTypeList)
|
||||
: this(serviceProvider, logger, httpContext)
|
||||
{
|
||||
AddTypes(lazyTypeList);
|
||||
}
|
||||
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("Use ctor specifying IServiceProvider instead")]
|
||||
protected LazyManyObjectsResolverBase(HttpContextBase httpContext, IEnumerable<Lazy<Type>> lazyTypeList)
|
||||
: this(new ActivatorServiceProvider(), LoggerResolver.Current.Logger, httpContext, lazyTypeList)
|
||||
{
|
||||
}
|
||||
|
||||
protected LazyManyObjectsResolverBase(IServiceProvider serviceProvider, ILogger logger, HttpContextBase httpContext, Func<IEnumerable<Type>> typeListProducerList)
|
||||
: this(serviceProvider, logger, httpContext)
|
||||
{
|
||||
_typeListProducerList.Add(typeListProducerList);
|
||||
}
|
||||
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("Use ctor specifying IServiceProvider instead")]
|
||||
protected LazyManyObjectsResolverBase(HttpContextBase httpContext, Func<IEnumerable<Type>> typeListProducerList)
|
||||
: this(new ActivatorServiceProvider(), LoggerResolver.Current.Logger, httpContext, typeListProducerList)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.CodeDom;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
@@ -9,23 +10,39 @@ using Umbraco.Core.Logging;
|
||||
namespace Umbraco.Core.ObjectResolution
|
||||
{
|
||||
/// <summary>
|
||||
/// The base class for all many-objects resolvers.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResolver">The type of the concrete resolver class.</typeparam>
|
||||
/// <typeparam name="TResolved">The type of the resolved objects.</typeparam>
|
||||
public abstract class ManyObjectsResolverBase<TResolver, TResolved> : ResolverBase<TResolver>
|
||||
where TResolved : class
|
||||
/// The base class for all many-objects resolvers.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResolver">The type of the concrete resolver class.</typeparam>
|
||||
/// <typeparam name="TResolved">The type of the resolved objects.</typeparam>
|
||||
public abstract class ManyObjectsResolverBase<TResolver, TResolved> : ResolverBase<TResolver>
|
||||
where TResolved : class
|
||||
where TResolver : ResolverBase
|
||||
{
|
||||
private Lazy<IEnumerable<TResolved>> _applicationInstances;
|
||||
private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim();
|
||||
private readonly string _httpContextKey;
|
||||
private readonly List<Type> _instanceTypes = new List<Type>();
|
||||
private IEnumerable<TResolved> _sortedValues;
|
||||
{
|
||||
private Lazy<IEnumerable<TResolved>> _applicationInstances;
|
||||
private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim();
|
||||
private readonly string _httpContextKey;
|
||||
private readonly List<Type> _instanceTypes = new List<Type>();
|
||||
private IEnumerable<TResolved> _sortedValues;
|
||||
|
||||
private int _defaultPluginWeight = 10;
|
||||
private int _defaultPluginWeight = 10;
|
||||
|
||||
#region Constructors
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Hack: This is purely here to allow for the container resolver to be used, we'll need to refactor all of this slowly till we're
|
||||
/// happy with the outcome
|
||||
/// </summary>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="types"></param>
|
||||
/// <param name="scope"></param>
|
||||
internal ManyObjectsResolverBase(ILogger logger, IEnumerable<Type> types, ObjectLifetimeScope scope = ObjectLifetimeScope.Application)
|
||||
{
|
||||
if (logger == null) throw new ArgumentNullException("logger");
|
||||
if (types == null) throw new ArgumentNullException("types");
|
||||
_instanceTypes = types.ToList();
|
||||
LifetimeScope = scope;
|
||||
Logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ManyObjectsResolverBase{TResolver, TResolved}"/> class with an empty list of objects,
|
||||
@@ -59,14 +76,6 @@ namespace Umbraco.Core.ObjectResolution
|
||||
InitializeAppInstances();
|
||||
}
|
||||
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("Use ctor specifying IServiceProvider instead")]
|
||||
protected ManyObjectsResolverBase(ObjectLifetimeScope scope = ObjectLifetimeScope.Application)
|
||||
: this(new ActivatorServiceProvider(), LoggerResolver.Current.Logger, scope)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ManyObjectsResolverBase{TResolver, TResolved}"/> class with an empty list of objects,
|
||||
/// with creation of objects based on an HttpRequest lifetime scope.
|
||||
@@ -76,26 +85,16 @@ namespace Umbraco.Core.ObjectResolution
|
||||
/// <param name="httpContext">The HttpContextBase corresponding to the HttpRequest.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="httpContext"/> is <c>null</c>.</exception>
|
||||
protected ManyObjectsResolverBase(IServiceProvider serviceProvider, ILogger logger, HttpContextBase httpContext)
|
||||
{
|
||||
{
|
||||
if (serviceProvider == null) throw new ArgumentNullException("serviceProvider");
|
||||
if (httpContext == null) throw new ArgumentNullException("httpContext");
|
||||
CanResolveBeforeFrozen = false;
|
||||
Logger = logger;
|
||||
LifetimeScope = ObjectLifetimeScope.HttpRequest;
|
||||
_httpContextKey = GetType().FullName;
|
||||
LifetimeScope = ObjectLifetimeScope.HttpRequest;
|
||||
_httpContextKey = GetType().FullName;
|
||||
ServiceProvider = serviceProvider;
|
||||
CurrentHttpContext = httpContext;
|
||||
_instanceTypes = new List<Type>();
|
||||
|
||||
InitializeAppInstances();
|
||||
}
|
||||
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("Use ctor specifying IServiceProvider instead")]
|
||||
protected ManyObjectsResolverBase(HttpContextBase httpContext)
|
||||
: this(new ActivatorServiceProvider(), LoggerResolver.Current.Logger, httpContext)
|
||||
{
|
||||
|
||||
_instanceTypes = new List<Type>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -110,57 +109,36 @@ namespace Umbraco.Core.ObjectResolution
|
||||
/// <exception cref="InvalidOperationException"><paramref name="scope"/> is per HttpRequest but the current HttpContext is null.</exception>
|
||||
protected ManyObjectsResolverBase(IServiceProvider serviceProvider, ILogger logger, IEnumerable<Type> value, ObjectLifetimeScope scope = ObjectLifetimeScope.Application)
|
||||
: this(serviceProvider, logger, scope)
|
||||
{
|
||||
_instanceTypes = value.ToList();
|
||||
}
|
||||
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("Use ctor specifying IServiceProvider instead")]
|
||||
protected ManyObjectsResolverBase(IEnumerable<Type> value, ObjectLifetimeScope scope = ObjectLifetimeScope.Application)
|
||||
: this(new ActivatorServiceProvider(), LoggerResolver.Current.Logger, value, scope)
|
||||
{
|
||||
|
||||
_instanceTypes = value.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ManyObjectsResolverBase{TResolver, TResolved}"/> class with an initial list of objects,
|
||||
/// with creation of objects based on an HttpRequest lifetime scope.
|
||||
/// </summary>
|
||||
/// <param name="httpContext">The HttpContextBase corresponding to the HttpRequest.</param>
|
||||
/// <param name="value">The list of object types.</param>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="httpContext"/> is <c>null</c>.</exception>
|
||||
[Obsolete("Use ctor specifying IServiceProvider instead")]
|
||||
protected ManyObjectsResolverBase(HttpContextBase httpContext, IEnumerable<Type> value)
|
||||
: this(new ActivatorServiceProvider(), LoggerResolver.Current.Logger, httpContext)
|
||||
{
|
||||
_instanceTypes = value.ToList();
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
private void InitializeAppInstances()
|
||||
{
|
||||
_applicationInstances = new Lazy<IEnumerable<TResolved>>(() => CreateInstances().ToArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the resolver can resolve objects before resolution is frozen.
|
||||
/// </summary>
|
||||
/// <remarks>This is false by default and is used for some special internal resolvers.</remarks>
|
||||
internal bool CanResolveBeforeFrozen { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the resolver can resolve objects before resolution is frozen.
|
||||
/// </summary>
|
||||
/// <remarks>This is false by default and is used for some special internal resolvers.</remarks>
|
||||
internal bool CanResolveBeforeFrozen { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of types to create instances from.
|
||||
/// </summary>
|
||||
protected virtual IEnumerable<Type> InstanceTypes
|
||||
{
|
||||
get { return _instanceTypes; }
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the list of types to create instances from.
|
||||
/// </summary>
|
||||
protected virtual IEnumerable<Type> InstanceTypes
|
||||
{
|
||||
get { return _instanceTypes; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="HttpContextBase"/> used to initialize this object, if any.
|
||||
/// </summary>
|
||||
/// <remarks>If not null, then <c>LifetimeScope</c> will be <c>ObjectLifetimeScope.HttpRequest</c>.</remarks>
|
||||
protected HttpContextBase CurrentHttpContext { get; private set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="HttpContextBase"/> used to initialize this object, if any.
|
||||
/// </summary>
|
||||
/// <remarks>If not null, then <c>LifetimeScope</c> will be <c>ObjectLifetimeScope.HttpRequest</c>.</remarks>
|
||||
protected HttpContextBase CurrentHttpContext { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns the service provider used to instantiate objects
|
||||
@@ -170,20 +148,20 @@ namespace Umbraco.Core.ObjectResolution
|
||||
public ILogger Logger { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the lifetime scope of resolved objects.
|
||||
/// </summary>
|
||||
protected ObjectLifetimeScope LifetimeScope { get; private set; }
|
||||
/// Gets or sets the lifetime scope of resolved objects.
|
||||
/// </summary>
|
||||
protected ObjectLifetimeScope LifetimeScope { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the resolved object instances, sorted by weight.
|
||||
/// </summary>
|
||||
/// <returns>The sorted resolved object instances.</returns>
|
||||
/// <remarks>
|
||||
/// <para>The order is based upon the <c>WeightedPluginAttribute</c> and <c>DefaultPluginWeight</c>.</para>
|
||||
/// <para>Weights are sorted ascendingly (lowest weights come first).</para>
|
||||
/// </remarks>
|
||||
protected IEnumerable<TResolved> GetSortedValues()
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the resolved object instances, sorted by weight.
|
||||
/// </summary>
|
||||
/// <returns>The sorted resolved object instances.</returns>
|
||||
/// <remarks>
|
||||
/// <para>The order is based upon the <c>WeightedPluginAttribute</c> and <c>DefaultPluginWeight</c>.</para>
|
||||
/// <para>Weights are sorted ascendingly (lowest weights come first).</para>
|
||||
/// </remarks>
|
||||
protected IEnumerable<TResolved> GetSortedValues()
|
||||
{
|
||||
if (_sortedValues == null)
|
||||
{
|
||||
var values = Values.ToList();
|
||||
@@ -191,199 +169,206 @@ namespace Umbraco.Core.ObjectResolution
|
||||
_sortedValues = values;
|
||||
}
|
||||
return _sortedValues;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the default type weight.
|
||||
/// </summary>
|
||||
/// <remarks>Determines the weight of types that do not have a <c>WeightedPluginAttribute</c> set on
|
||||
/// them, when calling <c>GetSortedValues</c>.</remarks>
|
||||
protected virtual int DefaultPluginWeight
|
||||
{
|
||||
get { return _defaultPluginWeight; }
|
||||
set { _defaultPluginWeight = value; }
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets or sets the default type weight.
|
||||
/// </summary>
|
||||
/// <remarks>Determines the weight of types that do not have a <c>WeightedPluginAttribute</c> set on
|
||||
/// them, when calling <c>GetSortedValues</c>.</remarks>
|
||||
protected virtual int DefaultPluginWeight
|
||||
{
|
||||
get { return _defaultPluginWeight; }
|
||||
set { _defaultPluginWeight = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the weight of an object for user with GetSortedValues
|
||||
/// </summary>
|
||||
/// <param name="o"></param>
|
||||
/// <returns></returns>
|
||||
protected virtual int GetObjectWeight(object o)
|
||||
{
|
||||
var type = o.GetType();
|
||||
var attr = type.GetCustomAttribute<WeightedPluginAttribute>(true);
|
||||
return attr == null ? DefaultPluginWeight : attr.Weight;
|
||||
}
|
||||
protected virtual int GetObjectWeight(object o)
|
||||
{
|
||||
var type = o.GetType();
|
||||
var attr = type.GetCustomAttribute<WeightedPluginAttribute>(true);
|
||||
return attr == null ? DefaultPluginWeight : attr.Weight;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the resolved object instances.
|
||||
/// </summary>
|
||||
/// <exception cref="InvalidOperationException"><c>CanResolveBeforeFrozen</c> is false, and resolution is not frozen.</exception>
|
||||
protected IEnumerable<TResolved> Values
|
||||
{
|
||||
get
|
||||
{
|
||||
using (Resolution.Reader(CanResolveBeforeFrozen))
|
||||
{
|
||||
// note: we apply .ToArray() to the output of CreateInstance() because that is an IEnumerable that
|
||||
// comes from the PluginManager we want to be _sure_ that it's not a Linq of some sort, but the
|
||||
// instances have actually been instanciated when we return.
|
||||
/// <summary>
|
||||
/// Gets the resolved object instances.
|
||||
/// </summary>
|
||||
/// <exception cref="InvalidOperationException"><c>CanResolveBeforeFrozen</c> is false, and resolution is not frozen.</exception>
|
||||
protected IEnumerable<TResolved> Values
|
||||
{
|
||||
get { return CreateValues(LifetimeScope); }
|
||||
}
|
||||
|
||||
switch (LifetimeScope)
|
||||
{
|
||||
case ObjectLifetimeScope.HttpRequest:
|
||||
/// <summary>
|
||||
/// Creates the values collection based on the scope
|
||||
/// </summary>
|
||||
/// <param name="scope"></param>
|
||||
/// <returns></returns>
|
||||
protected virtual IEnumerable<TResolved> CreateValues(ObjectLifetimeScope scope)
|
||||
{
|
||||
using (Resolution.Reader(CanResolveBeforeFrozen))
|
||||
{
|
||||
// note: we apply .ToArray() to the output of CreateInstance() because that is an IEnumerable that
|
||||
// comes from the PluginManager we want to be _sure_ that it's not a Linq of some sort, but the
|
||||
// instances have actually been instanciated when we return.
|
||||
|
||||
// create new instances per HttpContext
|
||||
if (CurrentHttpContext.Items[_httpContextKey] == null)
|
||||
switch (LifetimeScope)
|
||||
{
|
||||
case ObjectLifetimeScope.HttpRequest:
|
||||
|
||||
// create new instances per HttpContext
|
||||
if (CurrentHttpContext.Items[_httpContextKey] == null)
|
||||
{
|
||||
var instances = CreateInstances().ToArray();
|
||||
var disposableInstances = instances.OfType<IDisposable>();
|
||||
//Ensure anything resolved that is IDisposable is disposed when the request termintates
|
||||
foreach (var disposable in disposableInstances)
|
||||
{
|
||||
var instances = CreateInstances().ToArray();
|
||||
var disposableInstances = instances.OfType<IDisposable>();
|
||||
//Ensure anything resolved that is IDisposable is disposed when the request termintates
|
||||
foreach (var disposable in disposableInstances)
|
||||
{
|
||||
CurrentHttpContext.DisposeOnPipelineCompleted(disposable);
|
||||
}
|
||||
CurrentHttpContext.Items[_httpContextKey] = instances;
|
||||
CurrentHttpContext.DisposeOnPipelineCompleted(disposable);
|
||||
}
|
||||
return (TResolved[])CurrentHttpContext.Items[_httpContextKey];
|
||||
|
||||
case ObjectLifetimeScope.Application:
|
||||
CurrentHttpContext.Items[_httpContextKey] = instances;
|
||||
}
|
||||
return (TResolved[])CurrentHttpContext.Items[_httpContextKey];
|
||||
|
||||
return _applicationInstances.Value;
|
||||
case ObjectLifetimeScope.Application:
|
||||
|
||||
case ObjectLifetimeScope.Transient:
|
||||
default:
|
||||
// create new instances each time
|
||||
return CreateInstances().ToArray();
|
||||
}
|
||||
return _applicationInstances.Value;
|
||||
|
||||
case ObjectLifetimeScope.Transient:
|
||||
default:
|
||||
// create new instances each time
|
||||
return CreateInstances().ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the object instances for the types contained in the types collection.
|
||||
/// </summary>
|
||||
/// <returns>A list of objects of type <typeparamref name="TResolved"/>.</returns>
|
||||
protected virtual IEnumerable<TResolved> CreateInstances()
|
||||
{
|
||||
return ServiceProvider.CreateInstances<TResolved>(InstanceTypes, Logger);
|
||||
}
|
||||
/// <summary>
|
||||
/// Instantiates the object instances for the types contained in the types collection.
|
||||
/// </summary>
|
||||
/// <returns>A list of objects of type <typeparamref name="TResolved"/>.</returns>
|
||||
protected virtual IEnumerable<TResolved> CreateInstances()
|
||||
{
|
||||
return ServiceProvider.CreateInstances<TResolved>(InstanceTypes, Logger);
|
||||
}
|
||||
|
||||
#region Types collection manipulation
|
||||
#region Types collection manipulation
|
||||
|
||||
/// <summary>
|
||||
/// Removes a type.
|
||||
/// </summary>
|
||||
/// <param name="value">The type to remove.</param>
|
||||
/// <exception cref="InvalidOperationException">the resolver does not support removing types, or
|
||||
/// the type is not a valid type for the resolver.</exception>
|
||||
public virtual void RemoveType(Type value)
|
||||
{
|
||||
EnsureSupportsRemove();
|
||||
/// <summary>
|
||||
/// Removes a type.
|
||||
/// </summary>
|
||||
/// <param name="value">The type to remove.</param>
|
||||
/// <exception cref="InvalidOperationException">the resolver does not support removing types, or
|
||||
/// the type is not a valid type for the resolver.</exception>
|
||||
public virtual void RemoveType(Type value)
|
||||
{
|
||||
EnsureSupportsRemove();
|
||||
|
||||
using (Resolution.Configuration)
|
||||
using (var l = new UpgradeableReadLock(_lock))
|
||||
{
|
||||
EnsureCorrectType(value);
|
||||
using (Resolution.Configuration)
|
||||
using (var l = new UpgradeableReadLock(_lock))
|
||||
{
|
||||
EnsureCorrectType(value);
|
||||
|
||||
l.UpgradeToWriteLock();
|
||||
_instanceTypes.Remove(value);
|
||||
}
|
||||
}
|
||||
l.UpgradeToWriteLock();
|
||||
_instanceTypes.Remove(value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type to remove.</typeparam>
|
||||
/// <exception cref="InvalidOperationException">the resolver does not support removing types, or
|
||||
/// the type is not a valid type for the resolver.</exception>
|
||||
public void RemoveType<T>()
|
||||
/// <summary>
|
||||
/// Removes a type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type to remove.</typeparam>
|
||||
/// <exception cref="InvalidOperationException">the resolver does not support removing types, or
|
||||
/// the type is not a valid type for the resolver.</exception>
|
||||
public void RemoveType<T>()
|
||||
where T : TResolved
|
||||
{
|
||||
RemoveType(typeof(T));
|
||||
}
|
||||
{
|
||||
RemoveType(typeof(T));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds types.
|
||||
/// </summary>
|
||||
/// <param name="types">The types to add.</param>
|
||||
/// <remarks>The types are appended at the end of the list.</remarks>
|
||||
/// <exception cref="InvalidOperationException">the resolver does not support adding types, or
|
||||
/// a type is not a valid type for the resolver, or a type is already in the collection of types.</exception>
|
||||
protected void AddTypes(IEnumerable<Type> types)
|
||||
{
|
||||
EnsureSupportsAdd();
|
||||
/// <summary>
|
||||
/// Adds types.
|
||||
/// </summary>
|
||||
/// <param name="types">The types to add.</param>
|
||||
/// <remarks>The types are appended at the end of the list.</remarks>
|
||||
/// <exception cref="InvalidOperationException">the resolver does not support adding types, or
|
||||
/// a type is not a valid type for the resolver, or a type is already in the collection of types.</exception>
|
||||
protected void AddTypes(IEnumerable<Type> types)
|
||||
{
|
||||
EnsureSupportsAdd();
|
||||
|
||||
using (Resolution.Configuration)
|
||||
using (new WriteLock(_lock))
|
||||
{
|
||||
foreach(var t in types)
|
||||
{
|
||||
EnsureCorrectType(t);
|
||||
using (Resolution.Configuration)
|
||||
using (new WriteLock(_lock))
|
||||
{
|
||||
foreach (var t in types)
|
||||
{
|
||||
EnsureCorrectType(t);
|
||||
if (_instanceTypes.Contains(t))
|
||||
{
|
||||
throw new InvalidOperationException(string.Format(
|
||||
"Type {0} is already in the collection of types.", t.FullName));
|
||||
}
|
||||
_instanceTypes.Add(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
throw new InvalidOperationException(string.Format(
|
||||
"Type {0} is already in the collection of types.", t.FullName));
|
||||
}
|
||||
_instanceTypes.Add(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a type.
|
||||
/// </summary>
|
||||
/// <param name="value">The type to add.</param>
|
||||
/// <remarks>The type is appended at the end of the list.</remarks>
|
||||
/// <exception cref="InvalidOperationException">the resolver does not support adding types, or
|
||||
/// the type is not a valid type for the resolver, or the type is already in the collection of types.</exception>
|
||||
public virtual void AddType(Type value)
|
||||
{
|
||||
EnsureSupportsAdd();
|
||||
/// <summary>
|
||||
/// Adds a type.
|
||||
/// </summary>
|
||||
/// <param name="value">The type to add.</param>
|
||||
/// <remarks>The type is appended at the end of the list.</remarks>
|
||||
/// <exception cref="InvalidOperationException">the resolver does not support adding types, or
|
||||
/// the type is not a valid type for the resolver, or the type is already in the collection of types.</exception>
|
||||
public virtual void AddType(Type value)
|
||||
{
|
||||
EnsureSupportsAdd();
|
||||
|
||||
using (Resolution.Configuration)
|
||||
using (var l = new UpgradeableReadLock(_lock))
|
||||
{
|
||||
EnsureCorrectType(value);
|
||||
using (Resolution.Configuration)
|
||||
using (var l = new UpgradeableReadLock(_lock))
|
||||
{
|
||||
EnsureCorrectType(value);
|
||||
if (_instanceTypes.Contains(value))
|
||||
{
|
||||
throw new InvalidOperationException(string.Format(
|
||||
"Type {0} is already in the collection of types.", value.FullName));
|
||||
}
|
||||
{
|
||||
throw new InvalidOperationException(string.Format(
|
||||
"Type {0} is already in the collection of types.", value.FullName));
|
||||
}
|
||||
|
||||
l.UpgradeToWriteLock();
|
||||
_instanceTypes.Add(value);
|
||||
}
|
||||
}
|
||||
l.UpgradeToWriteLock();
|
||||
_instanceTypes.Add(value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type to add.</typeparam>
|
||||
/// <remarks>The type is appended at the end of the list.</remarks>
|
||||
/// <exception cref="InvalidOperationException">the resolver does not support adding types, or
|
||||
/// the type is not a valid type for the resolver, or the type is already in the collection of types.</exception>
|
||||
public void AddType<T>()
|
||||
/// <summary>
|
||||
/// Adds a type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type to add.</typeparam>
|
||||
/// <remarks>The type is appended at the end of the list.</remarks>
|
||||
/// <exception cref="InvalidOperationException">the resolver does not support adding types, or
|
||||
/// the type is not a valid type for the resolver, or the type is already in the collection of types.</exception>
|
||||
public void AddType<T>()
|
||||
where T : TResolved
|
||||
{
|
||||
AddType(typeof(T));
|
||||
}
|
||||
{
|
||||
AddType(typeof(T));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears the list of types
|
||||
/// </summary>
|
||||
/// <exception cref="InvalidOperationException">the resolver does not support clearing types.</exception>
|
||||
public virtual void Clear()
|
||||
{
|
||||
EnsureSupportsClear();
|
||||
/// <summary>
|
||||
/// Clears the list of types
|
||||
/// </summary>
|
||||
/// <exception cref="InvalidOperationException">the resolver does not support clearing types.</exception>
|
||||
public virtual void Clear()
|
||||
{
|
||||
EnsureSupportsClear();
|
||||
|
||||
using (Resolution.Configuration)
|
||||
using (new WriteLock(_lock))
|
||||
{
|
||||
_instanceTypes.Clear();
|
||||
}
|
||||
}
|
||||
using (Resolution.Configuration)
|
||||
using (new WriteLock(_lock))
|
||||
{
|
||||
_instanceTypes.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// WARNING! Do not use this unless you know what you are doing, clear all types registered and instances
|
||||
@@ -399,32 +384,32 @@ namespace Umbraco.Core.ObjectResolution
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts a type at the specified index.
|
||||
/// </summary>
|
||||
/// <param name="index">The zero-based index at which the type should be inserted.</param>
|
||||
/// <param name="value">The type to insert.</param>
|
||||
/// <exception cref="InvalidOperationException">the resolver does not support inserting types, or
|
||||
/// the type is not a valid type for the resolver, or the type is already in the collection of types.</exception>
|
||||
/// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> is out of range.</exception>
|
||||
public virtual void InsertType(int index, Type value)
|
||||
{
|
||||
EnsureSupportsInsert();
|
||||
/// <summary>
|
||||
/// Inserts a type at the specified index.
|
||||
/// </summary>
|
||||
/// <param name="index">The zero-based index at which the type should be inserted.</param>
|
||||
/// <param name="value">The type to insert.</param>
|
||||
/// <exception cref="InvalidOperationException">the resolver does not support inserting types, or
|
||||
/// the type is not a valid type for the resolver, or the type is already in the collection of types.</exception>
|
||||
/// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> is out of range.</exception>
|
||||
public virtual void InsertType(int index, Type value)
|
||||
{
|
||||
EnsureSupportsInsert();
|
||||
|
||||
using (Resolution.Configuration)
|
||||
using (var l = new UpgradeableReadLock(_lock))
|
||||
{
|
||||
EnsureCorrectType(value);
|
||||
using (Resolution.Configuration)
|
||||
using (var l = new UpgradeableReadLock(_lock))
|
||||
{
|
||||
EnsureCorrectType(value);
|
||||
if (_instanceTypes.Contains(value))
|
||||
{
|
||||
throw new InvalidOperationException(string.Format(
|
||||
"Type {0} is already in the collection of types.", value.FullName));
|
||||
}
|
||||
{
|
||||
throw new InvalidOperationException(string.Format(
|
||||
"Type {0} is already in the collection of types.", value.FullName));
|
||||
}
|
||||
|
||||
l.UpgradeToWriteLock();
|
||||
_instanceTypes.Insert(index, value);
|
||||
}
|
||||
}
|
||||
l.UpgradeToWriteLock();
|
||||
_instanceTypes.Insert(index, value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts a type at the beginning of the list.
|
||||
@@ -438,16 +423,16 @@ namespace Umbraco.Core.ObjectResolution
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts a type at the specified index.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type to insert.</typeparam>
|
||||
/// <param name="index">The zero-based index at which the type should be inserted.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> is out of range.</exception>
|
||||
public void InsertType<T>(int index)
|
||||
/// Inserts a type at the specified index.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type to insert.</typeparam>
|
||||
/// <param name="index">The zero-based index at which the type should be inserted.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> is out of range.</exception>
|
||||
public void InsertType<T>(int index)
|
||||
where T : TResolved
|
||||
{
|
||||
InsertType(index, typeof(T));
|
||||
}
|
||||
{
|
||||
InsertType(index, typeof(T));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts a type at the beginning of the list.
|
||||
@@ -458,68 +443,68 @@ namespace Umbraco.Core.ObjectResolution
|
||||
{
|
||||
InsertType(0, typeof(T));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts a type before a specified, already existing type.
|
||||
/// </summary>
|
||||
/// <param name="existingType">The existing type before which to insert.</param>
|
||||
/// <param name="value">The type to insert.</param>
|
||||
/// <exception cref="InvalidOperationException">the resolver does not support inserting types, or
|
||||
/// one of the types is not a valid type for the resolver, or the existing type is not in the collection,
|
||||
/// or the new type is already in the collection of types.</exception>
|
||||
public virtual void InsertTypeBefore(Type existingType, Type value)
|
||||
{
|
||||
EnsureSupportsInsert();
|
||||
|
||||
using (Resolution.Configuration)
|
||||
using (var l = new UpgradeableReadLock(_lock))
|
||||
{
|
||||
EnsureCorrectType(existingType);
|
||||
EnsureCorrectType(value);
|
||||
/// <summary>
|
||||
/// Inserts a type before a specified, already existing type.
|
||||
/// </summary>
|
||||
/// <param name="existingType">The existing type before which to insert.</param>
|
||||
/// <param name="value">The type to insert.</param>
|
||||
/// <exception cref="InvalidOperationException">the resolver does not support inserting types, or
|
||||
/// one of the types is not a valid type for the resolver, or the existing type is not in the collection,
|
||||
/// or the new type is already in the collection of types.</exception>
|
||||
public virtual void InsertTypeBefore(Type existingType, Type value)
|
||||
{
|
||||
EnsureSupportsInsert();
|
||||
|
||||
using (Resolution.Configuration)
|
||||
using (var l = new UpgradeableReadLock(_lock))
|
||||
{
|
||||
EnsureCorrectType(existingType);
|
||||
EnsureCorrectType(value);
|
||||
if (_instanceTypes.Contains(existingType) == false)
|
||||
{
|
||||
throw new InvalidOperationException(string.Format(
|
||||
"Type {0} is not in the collection of types.", existingType.FullName));
|
||||
}
|
||||
{
|
||||
throw new InvalidOperationException(string.Format(
|
||||
"Type {0} is not in the collection of types.", existingType.FullName));
|
||||
}
|
||||
if (_instanceTypes.Contains(value))
|
||||
{
|
||||
throw new InvalidOperationException(string.Format(
|
||||
"Type {0} is already in the collection of types.", value.FullName));
|
||||
}
|
||||
{
|
||||
throw new InvalidOperationException(string.Format(
|
||||
"Type {0} is already in the collection of types.", value.FullName));
|
||||
}
|
||||
int index = _instanceTypes.IndexOf(existingType);
|
||||
|
||||
l.UpgradeToWriteLock();
|
||||
_instanceTypes.Insert(index, value);
|
||||
}
|
||||
}
|
||||
l.UpgradeToWriteLock();
|
||||
_instanceTypes.Insert(index, value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts a type before a specified, already existing type.
|
||||
/// </summary>
|
||||
/// <typeparam name="TExisting">The existing type before which to insert.</typeparam>
|
||||
/// <typeparam name="T">The type to insert.</typeparam>
|
||||
/// <exception cref="InvalidOperationException">the resolver does not support inserting types, or
|
||||
/// one of the types is not a valid type for the resolver, or the existing type is not in the collection,
|
||||
/// or the new type is already in the collection of types.</exception>
|
||||
public void InsertTypeBefore<TExisting, T>()
|
||||
/// <summary>
|
||||
/// Inserts a type before a specified, already existing type.
|
||||
/// </summary>
|
||||
/// <typeparam name="TExisting">The existing type before which to insert.</typeparam>
|
||||
/// <typeparam name="T">The type to insert.</typeparam>
|
||||
/// <exception cref="InvalidOperationException">the resolver does not support inserting types, or
|
||||
/// one of the types is not a valid type for the resolver, or the existing type is not in the collection,
|
||||
/// or the new type is already in the collection of types.</exception>
|
||||
public void InsertTypeBefore<TExisting, T>()
|
||||
where TExisting : TResolved
|
||||
where T : TResolved
|
||||
{
|
||||
InsertTypeBefore(typeof(TExisting), typeof(T));
|
||||
}
|
||||
{
|
||||
InsertTypeBefore(typeof(TExisting), typeof(T));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value indicating whether the specified type is already in the collection of types.
|
||||
/// </summary>
|
||||
/// <param name="value">The type to look for.</param>
|
||||
/// <returns>A value indicating whether the type is already in the collection of types.</returns>
|
||||
public virtual bool ContainsType(Type value)
|
||||
{
|
||||
using (new ReadLock(_lock))
|
||||
{
|
||||
return _instanceTypes.Contains(value);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns a value indicating whether the specified type is already in the collection of types.
|
||||
/// </summary>
|
||||
/// <param name="value">The type to look for.</param>
|
||||
/// <returns>A value indicating whether the type is already in the collection of types.</returns>
|
||||
public virtual bool ContainsType(Type value)
|
||||
{
|
||||
using (new ReadLock(_lock))
|
||||
{
|
||||
return _instanceTypes.Contains(value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the types in the collection of types.
|
||||
@@ -536,27 +521,27 @@ namespace Umbraco.Core.ObjectResolution
|
||||
return types;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value indicating whether the specified type is already in the collection of types.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type to look for.</typeparam>
|
||||
/// <returns>A value indicating whether the type is already in the collection of types.</returns>
|
||||
public bool ContainsType<T>()
|
||||
/// <summary>
|
||||
/// Returns a value indicating whether the specified type is already in the collection of types.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type to look for.</typeparam>
|
||||
/// <returns>A value indicating whether the type is already in the collection of types.</returns>
|
||||
public bool ContainsType<T>()
|
||||
where T : TResolved
|
||||
{
|
||||
return ContainsType(typeof(T));
|
||||
}
|
||||
{
|
||||
return ContainsType(typeof(T));
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Returns a WriteLock to use when modifying collections
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected WriteLock GetWriteLock()
|
||||
{
|
||||
return new WriteLock(_lock);
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns a WriteLock to use when modifying collections
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected WriteLock GetWriteLock()
|
||||
{
|
||||
return new WriteLock(_lock);
|
||||
}
|
||||
|
||||
#region Type utilities
|
||||
|
||||
@@ -581,70 +566,71 @@ namespace Umbraco.Core.ObjectResolution
|
||||
/// </summary>
|
||||
/// <exception cref="InvalidOperationException">The resolver does not support removing types.</exception>
|
||||
protected void EnsureSupportsRemove()
|
||||
{
|
||||
if (SupportsRemove == false)
|
||||
{
|
||||
if (SupportsRemove == false)
|
||||
throw new InvalidOperationException("This resolver does not support removing types");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensures that the resolver supports clearing types.
|
||||
/// </summary>
|
||||
/// <exception cref="InvalidOperationException">The resolver does not support clearing types.</exception>
|
||||
protected void EnsureSupportsClear() {
|
||||
if (SupportsClear == false)
|
||||
protected void EnsureSupportsClear()
|
||||
{
|
||||
if (SupportsClear == false)
|
||||
throw new InvalidOperationException("This resolver does not support clearing types");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensures that the resolver supports adding types.
|
||||
/// </summary>
|
||||
/// <exception cref="InvalidOperationException">The resolver does not support adding types.</exception>
|
||||
protected void EnsureSupportsAdd()
|
||||
{
|
||||
if (SupportsAdd == false)
|
||||
{
|
||||
if (SupportsAdd == false)
|
||||
throw new InvalidOperationException("This resolver does not support adding new types");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensures that the resolver supports inserting types.
|
||||
/// </summary>
|
||||
/// <exception cref="InvalidOperationException">The resolver does not support inserting types.</exception>
|
||||
protected void EnsureSupportsInsert()
|
||||
{
|
||||
if (SupportsInsert == false)
|
||||
{
|
||||
if (SupportsInsert == false)
|
||||
throw new InvalidOperationException("This resolver does not support inserting new types");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the resolver supports adding types.
|
||||
/// </summary>
|
||||
protected virtual bool SupportsAdd
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
protected virtual bool SupportsAdd
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the resolver supports inserting types.
|
||||
/// </summary>
|
||||
protected virtual bool SupportsInsert
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the resolver supports clearing types.
|
||||
/// </summary>
|
||||
protected virtual bool SupportsClear
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the resolver supports removing types.
|
||||
/// </summary>
|
||||
protected virtual bool SupportsRemove
|
||||
{
|
||||
get { return true; }
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Umbraco.Core.LightInject;
|
||||
|
||||
namespace Umbraco.Core.ObjectResolution
|
||||
{
|
||||
@@ -48,6 +49,12 @@ namespace Umbraco.Core.ObjectResolution
|
||||
|
||||
}
|
||||
|
||||
internal ResolverBase(IServiceContainer container)
|
||||
: base(() => Reset())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the resolver singleton instance.
|
||||
/// </summary>
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Threading;
|
||||
|
||||
namespace Umbraco.Core.ObjectResolution
|
||||
{
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// The base class for all single-object resolvers.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResolver">The type of the concrete resolver class.</typeparam>
|
||||
@@ -86,7 +86,7 @@ namespace Umbraco.Core.ObjectResolution
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the resolved object instance is null.
|
||||
/// </summary>
|
||||
public bool HasValue
|
||||
public virtual bool HasValue
|
||||
{
|
||||
get { return _value != null; }
|
||||
}
|
||||
@@ -98,7 +98,7 @@ namespace Umbraco.Core.ObjectResolution
|
||||
/// <exception cref="ArgumentNullException">value is set to null, but cannot be null (<c>CanBeNull</c> is <c>false</c>).</exception>
|
||||
/// <exception cref="InvalidOperationException">value is read and is null, but cannot be null (<c>CanBeNull</c> is <c>false</c>),
|
||||
/// or value is set (read) and resolution is (not) frozen.</exception>
|
||||
protected TResolved Value
|
||||
protected virtual TResolved Value
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace Umbraco.Core
|
||||
/// <param name="detectChanges"></param>
|
||||
/// <param name="serviceProvider"></param>
|
||||
/// <param name="runtimeCache"></param>
|
||||
internal PluginManager(IServiceProvider serviceProvider, IRuntimeCacheProvider runtimeCache, ProfilingLogger logger, bool detectChanges = true)
|
||||
public PluginManager(IServiceProvider serviceProvider, IRuntimeCacheProvider runtimeCache, ProfilingLogger logger, bool detectChanges = true)
|
||||
{
|
||||
if (serviceProvider == null) throw new ArgumentNullException("serviceProvider");
|
||||
if (runtimeCache == null) throw new ArgumentNullException("runtimeCache");
|
||||
@@ -494,7 +494,7 @@ namespace Umbraco.Core
|
||||
/// <returns></returns>
|
||||
internal IEnumerable<Type> ResolveApplicationStartupHandlers()
|
||||
{
|
||||
return ResolveTypes<IApplicationStartupHandler>();
|
||||
return ResolveTypes<IApplicationEventHandler>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -5,6 +5,9 @@ namespace Umbraco.Core.Profiling
|
||||
/// <summary>
|
||||
/// A resolver exposing the current profiler
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// NOTE: This is a 'special' resolver in that it gets initialized before most other things, it cannot use IoC so it cannot implement ContainerObjectResolverBase
|
||||
/// </remarks>
|
||||
internal class ProfilerResolver : SingleObjectResolverBase<ProfilerResolver, IProfiler>
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -10,20 +10,19 @@ namespace Umbraco.Core.Profiling
|
||||
/// <summary>
|
||||
/// A profiler used for web based activity based on the MiniProfiler framework
|
||||
/// </summary>
|
||||
internal class WebProfiler : IProfiler
|
||||
internal class WebProfiler : ApplicationEventHandler, IProfiler
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
///Binds to application events to enable the MiniProfiler
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Binds to application events to enable the MiniProfiler
|
||||
/// </remarks>
|
||||
internal WebProfiler()
|
||||
/// <param name="umbracoApplication"></param>
|
||||
/// <param name="applicationContext"></param>
|
||||
protected override void ApplicationInitialized(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
|
||||
{
|
||||
UmbracoApplicationBase.ApplicationInit += UmbracoApplicationApplicationInit;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Handle the Init event o fthe UmbracoApplication which allows us to subscribe to the HttpApplication events
|
||||
/// </summary>
|
||||
|
||||
@@ -20,12 +20,6 @@ namespace Umbraco.Core.PropertyEditors
|
||||
{
|
||||
}
|
||||
|
||||
[Obsolete("Use the ctor specifying a PluginManager instead")]
|
||||
public PropertyEditorResolver(Func<IEnumerable<Type>> typeListProducerList)
|
||||
: base(typeListProducerList, ObjectLifetimeScope.Application)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the property editors
|
||||
/// </summary>
|
||||
|
||||
@@ -23,16 +23,16 @@ namespace Umbraco.Core.Standalone
|
||||
|
||||
}
|
||||
|
||||
protected override void InitializeApplicationEventsResolver()
|
||||
{
|
||||
base.InitializeApplicationEventsResolver();
|
||||
//protected override void InitializeApplicationEventsResolver()
|
||||
//{
|
||||
// base.InitializeApplicationEventsResolver();
|
||||
|
||||
foreach (var type in _handlersToAdd)
|
||||
ApplicationEventsResolver.Current.AddType(type);
|
||||
// foreach (var type in _handlersToAdd)
|
||||
// ApplicationEventsResolver.Current.AddType(type);
|
||||
|
||||
foreach (var type in _handlersToRemove)
|
||||
ApplicationEventsResolver.Current.RemoveType(type);
|
||||
}
|
||||
// foreach (var type in _handlersToRemove)
|
||||
// ApplicationEventsResolver.Current.RemoveType(type);
|
||||
//}
|
||||
|
||||
protected override void InitializeResolvers()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Manifest;
|
||||
|
||||
namespace Umbraco.Core.Strategies
|
||||
{
|
||||
public sealed class ManifestWatcherHandler : ApplicationEventHandler
|
||||
{
|
||||
private ManifestWatcher _mw;
|
||||
|
||||
protected override void ApplicationInitialized(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
|
||||
{
|
||||
UmbracoApplicationBase.ApplicationEnd += app_ApplicationEnd;
|
||||
}
|
||||
|
||||
void app_ApplicationEnd(object sender, EventArgs e)
|
||||
{
|
||||
if (_mw != null)
|
||||
{
|
||||
_mw.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
|
||||
{
|
||||
_mw = new ManifestWatcher(applicationContext.ProfilingLogger.Logger);
|
||||
_mw.Start(Directory.GetDirectories(IOHelper.MapPath("~/App_Plugins/")));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -929,7 +929,7 @@ namespace Umbraco.Core
|
||||
// as the ShortStringHelper is too important, so as long as it's not there
|
||||
// already, we use a default one. That should never happen, but...
|
||||
Logging.LogHelper.Warn<IShortStringHelper>("ShortStringHelperResolver.HasCurrent == false, fallback to default.");
|
||||
_helper = new DefaultShortStringHelper().WithDefaultConfig();
|
||||
_helper = new DefaultShortStringHelper(UmbracoConfig.For.UmbracoSettings()).WithDefaultConfig();
|
||||
_helper.Freeze();
|
||||
return _helper;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Globalization;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
|
||||
namespace Umbraco.Core.Strings
|
||||
{
|
||||
@@ -18,10 +19,13 @@ namespace Umbraco.Core.Strings
|
||||
/// </remarks>
|
||||
public class DefaultShortStringHelper : IShortStringHelper
|
||||
{
|
||||
private readonly IUmbracoSettingsSection _settings;
|
||||
|
||||
#region Ctor and vars
|
||||
|
||||
public DefaultShortStringHelper()
|
||||
public DefaultShortStringHelper(IUmbracoSettingsSection settings)
|
||||
{
|
||||
_settings = settings;
|
||||
InitializeLegacyUrlReplaceCharacters();
|
||||
}
|
||||
|
||||
@@ -57,7 +61,7 @@ namespace Umbraco.Core.Strings
|
||||
|
||||
private void InitializeLegacyUrlReplaceCharacters()
|
||||
{
|
||||
foreach (var node in UmbracoConfig.For.UmbracoSettings().RequestHandler.CharCollection)
|
||||
foreach (var node in _settings.RequestHandler.CharCollection)
|
||||
{
|
||||
if(string.IsNullOrEmpty(node.Char) == false)
|
||||
_urlReplaceCharacters[node.Char] = node.Replacement;
|
||||
@@ -146,7 +150,7 @@ namespace Umbraco.Core.Strings
|
||||
PreFilter = ApplyUrlReplaceCharacters,
|
||||
PostFilter = x => CutMaxLength(x, 240),
|
||||
IsTerm = (c, leading) => char.IsLetterOrDigit(c) || c == '_', // letter, digit or underscore
|
||||
StringType = (UmbracoConfig.For.UmbracoSettings().RequestHandler.ConvertUrlsToAscii ? CleanStringType.Ascii : CleanStringType.Utf8) | CleanStringType.LowerCase,
|
||||
StringType = (_settings.RequestHandler.ConvertUrlsToAscii ? CleanStringType.Ascii : CleanStringType.Utf8) | CleanStringType.LowerCase,
|
||||
BreakTermsOnUpper = false,
|
||||
Separator = '-'
|
||||
}).WithConfig(CleanStringType.FileName, new Config
|
||||
@@ -323,7 +327,7 @@ function validateSafeAlias(input, value, immediate, callback) {{
|
||||
public string GetShortStringServicesJavaScript(string controllerPath)
|
||||
{
|
||||
return string.Format(SssjsFormat,
|
||||
UmbracoConfig.For.UmbracoSettings().Content.ForceSafeAliases ? "true" : "false", controllerPath);
|
||||
_settings.Content.ForceSafeAliases ? "true" : "false", controllerPath);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -1,12 +1,37 @@
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
using Umbraco.Core.LightInject;
|
||||
using Umbraco.Core.ObjectResolution;
|
||||
|
||||
namespace Umbraco.Core.Strings
|
||||
{
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// Resolves the IShortStringHelper object
|
||||
/// </summary>
|
||||
public sealed class ShortStringHelperResolver : SingleObjectResolverBase<ShortStringHelperResolver, IShortStringHelper>
|
||||
{
|
||||
/// </summary>
|
||||
public sealed class ShortStringHelperResolver : ContainerSingleObjectResolver<ShortStringHelperResolver, IShortStringHelper>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes the resolver to use IoC
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
/// <param name="implementationType"></param>
|
||||
internal ShortStringHelperResolver(IServiceContainer container, Type implementationType)
|
||||
: base(container, implementationType)
|
||||
{
|
||||
Resolution.Frozen += (sender, args) => Value.Freeze();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the resolver to use IoC
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
/// <param name="implementationType"></param>
|
||||
internal ShortStringHelperResolver(IServiceContainer container, Expression<Func<IServiceFactory, IShortStringHelper>> implementationType)
|
||||
: base(container, implementationType)
|
||||
{
|
||||
Resolution.Frozen += (sender, args) => Value.Freeze();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ShortStringHelperResolver"/> class with an instance of a helper.
|
||||
/// </summary>
|
||||
@@ -17,24 +42,24 @@ namespace Umbraco.Core.Strings
|
||||
{
|
||||
Resolution.Frozen += (sender, args) => Value.Freeze();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Sets the helper.
|
||||
/// </summary>
|
||||
/// Sets the helper.
|
||||
/// </summary>
|
||||
/// <param name="helper">The helper.</param>
|
||||
/// <remarks>For developers, at application startup.</remarks>
|
||||
/// <remarks>For developers, at application startup.</remarks>
|
||||
public void SetHelper(IShortStringHelper helper)
|
||||
{
|
||||
{
|
||||
Value = helper;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the helper.
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
/// Gets the helper.
|
||||
/// </summary>
|
||||
public IShortStringHelper Helper
|
||||
{
|
||||
get { return Value; }
|
||||
}
|
||||
{
|
||||
get { return Value; }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.LightInject;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.ObjectResolution;
|
||||
|
||||
@@ -8,28 +9,40 @@ namespace Umbraco.Core.Strings
|
||||
/// <summary>
|
||||
/// Resolves IUrlSegmentProvider objects.
|
||||
/// </summary>
|
||||
public sealed class UrlSegmentProviderResolver : ManyObjectsResolverBase<UrlSegmentProviderResolver, IUrlSegmentProvider>
|
||||
public sealed class UrlSegmentProviderResolver : ContainerManyObjectsResolver<UrlSegmentProviderResolver, IUrlSegmentProvider>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UrlSegmentProviderResolver"/> class with an initial list of provider types.
|
||||
/// ONLY for testing
|
||||
/// </summary>
|
||||
/// <param name="serviceProvider"></param>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="providerTypes"></param>
|
||||
[Obsolete("Used only for Tests - should remove")]
|
||||
internal UrlSegmentProviderResolver(IServiceProvider serviceProvider, ILogger logger, params Type[] providerTypes)
|
||||
: base(serviceProvider, logger, providerTypes)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UrlSegmentProviderResolver"/> class with an initial list of provider types.
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="providerTypes">The list of provider types.</param>
|
||||
/// <remarks>The resolver is created by the <c>WebBootManager</c> and thus the constructor remains internal.</remarks>
|
||||
internal UrlSegmentProviderResolver(IServiceProvider serviceProvider, ILogger logger, IEnumerable<Type> providerTypes)
|
||||
: base(serviceProvider, logger, providerTypes)
|
||||
internal UrlSegmentProviderResolver(IServiceContainer container, ILogger logger, IEnumerable<Type> providerTypes)
|
||||
: base(container, logger, providerTypes)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UrlSegmentProviderResolver"/> class with an initial list of provider types.
|
||||
/// </summary>
|
||||
/// <param name="serviceProvider"></param>
|
||||
/// <param name="container"></param>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="providerTypes">The list of provider types.</param>
|
||||
/// <remarks>The resolver is created by the <c>WebBootManager</c> and thus the constructor remains internal.</remarks>
|
||||
internal UrlSegmentProviderResolver(IServiceProvider serviceProvider, ILogger logger, params Type[] providerTypes)
|
||||
: base(serviceProvider, logger, providerTypes)
|
||||
internal UrlSegmentProviderResolver(IServiceContainer container, ILogger logger, params Type[] providerTypes)
|
||||
: base(container, logger, providerTypes)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -16,8 +16,8 @@ namespace Umbraco.Core.Sync
|
||||
{
|
||||
private readonly IEnumerable<IServer> _servers;
|
||||
|
||||
public ConfigServerRegistrar()
|
||||
: this(UmbracoConfig.For.UmbracoSettings().DistributedCall.Servers)
|
||||
public ConfigServerRegistrar(IUmbracoSettingsSection settings)
|
||||
: this(settings.DistributedCall.Servers)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,32 @@
|
||||
using Umbraco.Core.ObjectResolution;
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
using Umbraco.Core.LightInject;
|
||||
using Umbraco.Core.ObjectResolution;
|
||||
|
||||
namespace Umbraco.Core.Sync
|
||||
{
|
||||
/// <summary>
|
||||
/// A resolver to return the currently registered IServerMessenger object
|
||||
/// </summary>
|
||||
public sealed class ServerMessengerResolver : SingleObjectResolverBase<ServerMessengerResolver, IServerMessenger>
|
||||
public sealed class ServerMessengerResolver : ContainerSingleObjectResolver<ServerMessengerResolver, IServerMessenger>
|
||||
{
|
||||
internal ServerMessengerResolver(IServerMessenger factory)
|
||||
: base(factory)
|
||||
/// <summary>
|
||||
/// Initialize a new instance of the <see cref="SingleObjectResolverBase{TResolver, TResolved}"/> class with an instance of the resolved object.
|
||||
/// </summary>
|
||||
/// <param name="value">An instance of the resolved object.</param>
|
||||
/// <remarks>By default <c>CanBeNull</c> is false, so <c>value</c> has to be non-null, or <c>Value</c> has to be
|
||||
/// initialized before being accessed, otherwise an exception will be thrown when reading it.</remarks>
|
||||
public ServerMessengerResolver(IServerMessenger value) : base(value)
|
||||
{
|
||||
}
|
||||
|
||||
internal ServerMessengerResolver(IServiceContainer container, Type implementationType)
|
||||
: base(container, implementationType)
|
||||
{
|
||||
}
|
||||
|
||||
internal ServerMessengerResolver(IServiceContainer container, Expression<Func<IServiceFactory, IServerMessenger>> implementationType)
|
||||
: base(container, implementationType)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,32 @@
|
||||
using Umbraco.Core.ObjectResolution;
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
using Umbraco.Core.LightInject;
|
||||
using Umbraco.Core.ObjectResolution;
|
||||
|
||||
namespace Umbraco.Core.Sync
|
||||
{
|
||||
/// <summary>
|
||||
/// The resolver to return the currently registered IServerRegistrar object
|
||||
/// </summary>
|
||||
public sealed class ServerRegistrarResolver : SingleObjectResolverBase<ServerRegistrarResolver, IServerRegistrar>
|
||||
public sealed class ServerRegistrarResolver : ContainerSingleObjectResolver<ServerRegistrarResolver, IServerRegistrar>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initialize a new instance of the <see cref="SingleObjectResolverBase{TResolver, TResolved}"/> class with an instance of the resolved object.
|
||||
/// </summary>
|
||||
/// <param name="value">An instance of the resolved object.</param>
|
||||
/// <remarks>By default <c>CanBeNull</c> is false, so <c>value</c> has to be non-null, or <c>Value</c> has to be
|
||||
/// initialized before being accessed, otherwise an exception will be thrown when reading it.</remarks>
|
||||
public ServerRegistrarResolver(IServerRegistrar value) : base(value)
|
||||
{
|
||||
}
|
||||
|
||||
internal ServerRegistrarResolver(IServerRegistrar factory)
|
||||
: base(factory)
|
||||
internal ServerRegistrarResolver(IServiceContainer container, Type implementationType)
|
||||
: base(container, implementationType)
|
||||
{
|
||||
}
|
||||
|
||||
internal ServerRegistrarResolver(IServiceContainer container, Expression<Func<IServiceFactory, IServerRegistrar>> implementationType)
|
||||
: base(container, implementationType)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -294,8 +294,12 @@
|
||||
<Compile Include="HideFromTypeFinderAttribute.cs" />
|
||||
<Compile Include="IApplicationEventHandler.cs" />
|
||||
<Compile Include="IDisposeOnRequestEnd.cs" />
|
||||
<Compile Include="LightInject\LightInject.cs" />
|
||||
<Compile Include="LightInject\LightInjectExtensions.cs" />
|
||||
<Compile Include="Models\AuditItem.cs" />
|
||||
<Compile Include="Models\AuditType.cs" />
|
||||
<Compile Include="ObjectResolution\ContainerManyObjectsResolver.cs" />
|
||||
<Compile Include="ObjectResolution\ContainerSingleObjectResolver.cs" />
|
||||
<Compile Include="Persistence\Factories\TaskFactory.cs" />
|
||||
<Compile Include="Persistence\Migrations\Upgrades\TargetVersionSevenThreeZero\RemoveStylesheetDataAndTables.cs" />
|
||||
<Compile Include="Persistence\Repositories\AuditRepository.cs" />
|
||||
@@ -316,6 +320,7 @@
|
||||
<Compile Include="Services\ITaskService.cs" />
|
||||
<Compile Include="Services\RepositoryService.cs" />
|
||||
<Compile Include="Services\TaskService.cs" />
|
||||
<Compile Include="Strategies\ManifestWatcherHandler.cs" />
|
||||
<Compile Include="Strings\Css\StylesheetHelper.cs" />
|
||||
<Compile Include="Models\IPartialView.cs" />
|
||||
<Compile Include="Persistence\DatabaseSchemaHelper.cs" />
|
||||
|
||||
@@ -21,13 +21,19 @@ namespace Umbraco.Core
|
||||
public abstract class UmbracoApplicationBase : System.Web.HttpApplication
|
||||
{
|
||||
|
||||
public static event EventHandler ApplicationStarting;
|
||||
public static event EventHandler ApplicationStarted;
|
||||
public event EventHandler ApplicationStarting;
|
||||
public event EventHandler ApplicationStarted;
|
||||
|
||||
/// <summary>
|
||||
/// Called when the HttpApplication.Init() is fired, allows developers to subscribe to the HttpApplication events
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Needs to be static otherwise null refs occur - though I don't know why
|
||||
/// </remarks>
|
||||
public static event EventHandler ApplicationInit;
|
||||
public static event EventHandler ApplicationError;
|
||||
public static event EventHandler ApplicationEnd;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Boots up the Umbraco application
|
||||
@@ -44,7 +50,7 @@ namespace Umbraco.Core
|
||||
.Complete(appContext => OnApplicationStarted(sender, e));
|
||||
|
||||
//And now we can dispose of our startup handlers - save some memory
|
||||
ApplicationEventsResolver.Current.Dispose();
|
||||
//ApplicationEventsResolver.Current.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -106,7 +112,8 @@ namespace Umbraco.Core
|
||||
/// <param name="e"></param>
|
||||
protected virtual void OnApplicationError(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
EventHandler handler = ApplicationError;
|
||||
if (handler != null) handler(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
protected void Application_Error(object sender, EventArgs e)
|
||||
@@ -134,7 +141,8 @@ namespace Umbraco.Core
|
||||
/// <param name="e"></param>
|
||||
protected virtual void OnApplicationEnd(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
EventHandler handler = ApplicationEnd;
|
||||
if (handler != null) handler(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
protected void Application_End(object sender, EventArgs e)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<packages>
|
||||
<package id="AutoMapper" version="3.0.0" targetFramework="net45" />
|
||||
<package id="HtmlAgilityPack" version="1.4.6" targetFramework="net45" />
|
||||
<package id="LightInject.Source" version="3.0.2.2" targetFramework="net45" />
|
||||
<package id="log4net-mediumtrust" version="2.0.0" targetFramework="net40" />
|
||||
<package id="Microsoft.AspNet.Mvc" version="4.0.30506.0" targetFramework="net40" />
|
||||
<package id="Microsoft.AspNet.Razor" version="2.0.30506.0" targetFramework="net40" />
|
||||
|
||||
@@ -1,155 +1,143 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.ObjectResolution;
|
||||
using Umbraco.Core.Persistence.SqlSyntax;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using umbraco.interfaces;
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
//using System.Text;
|
||||
//using System.Web;
|
||||
//using Moq;
|
||||
//using NUnit.Framework;
|
||||
//using Umbraco.Core;
|
||||
//using Umbraco.Core.Configuration;
|
||||
//using Umbraco.Core.Logging;
|
||||
//using Umbraco.Core.ObjectResolution;
|
||||
//using Umbraco.Core.Persistence.SqlSyntax;
|
||||
//using Umbraco.Tests.TestHelpers;
|
||||
//using umbraco.interfaces;
|
||||
|
||||
namespace Umbraco.Tests.BootManagers
|
||||
{
|
||||
[TestFixture]
|
||||
public class CoreBootManagerTests : BaseUmbracoApplicationTest
|
||||
{
|
||||
//namespace Umbraco.Tests.BootManagers
|
||||
//{
|
||||
// [TestFixture]
|
||||
// public class CoreBootManagerTests : BaseUmbracoApplicationTest
|
||||
// {
|
||||
|
||||
private TestApp _testApp;
|
||||
// private TestApp _testApp;
|
||||
|
||||
[SetUp]
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
_testApp = new TestApp();
|
||||
}
|
||||
// [SetUp]
|
||||
// public override void Initialize()
|
||||
// {
|
||||
// base.Initialize();
|
||||
// _testApp = new TestApp();
|
||||
// }
|
||||
|
||||
[TearDown]
|
||||
public override void TearDown()
|
||||
{
|
||||
base.TearDown();
|
||||
// [TearDown]
|
||||
// public override void TearDown()
|
||||
// {
|
||||
// base.TearDown();
|
||||
|
||||
_testApp = null;
|
||||
}
|
||||
// _testApp = null;
|
||||
// }
|
||||
|
||||
protected override void FreezeResolution()
|
||||
{
|
||||
//don't freeze resolution, we'll do that in the boot manager
|
||||
}
|
||||
// protected override void FreezeResolution()
|
||||
// {
|
||||
// //don't freeze resolution, we'll do that in the boot manager
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// test application using a CoreBootManager instance to boot
|
||||
/// </summary>
|
||||
public class TestApp : UmbracoApplicationBase
|
||||
{
|
||||
protected override IBootManager GetBootManager()
|
||||
{
|
||||
return new TestBootManager(this);
|
||||
}
|
||||
}
|
||||
// /// <summary>
|
||||
// /// test application using a CoreBootManager instance to boot
|
||||
// /// </summary>
|
||||
// public class TestApp : UmbracoApplicationBase
|
||||
// {
|
||||
// protected override IBootManager GetBootManager()
|
||||
// {
|
||||
// return new TestBootManager(this);
|
||||
// }
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// Test boot manager to add a custom application event handler
|
||||
/// </summary>
|
||||
public class TestBootManager : CoreBootManager
|
||||
{
|
||||
public TestBootManager(UmbracoApplicationBase umbracoApplication)
|
||||
: base(umbracoApplication)
|
||||
{
|
||||
}
|
||||
// /// <summary>
|
||||
// /// Test boot manager to add a custom application event handler
|
||||
// /// </summary>
|
||||
// public class TestBootManager : CoreBootManager
|
||||
// {
|
||||
// public TestBootManager(UmbracoApplicationBase umbracoApplication)
|
||||
// : base(umbracoApplication)
|
||||
// {
|
||||
// }
|
||||
|
||||
protected override void InitializeApplicationEventsResolver()
|
||||
{
|
||||
//create an empty resolver so we can add our own custom ones (don't type find)
|
||||
ApplicationEventsResolver.Current = new ApplicationEventsResolver(
|
||||
new ActivatorServiceProvider(), Mock.Of<ILogger>(),
|
||||
new Type[]
|
||||
{
|
||||
typeof(LegacyStartupHandler),
|
||||
typeof(TestApplicationEventHandler)
|
||||
})
|
||||
{
|
||||
CanResolveBeforeFrozen = true
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
// //TODO: For this test to work we need to udpate the multiple objects resolver to IoC, currently
|
||||
// // the app events are purely IoC in the Core Boot manager
|
||||
|
||||
/// <summary>
|
||||
/// Test legacy startup handler
|
||||
/// </summary>
|
||||
public class LegacyStartupHandler : IApplicationStartupHandler
|
||||
{
|
||||
public static bool Initialized = false;
|
||||
// protected override void InitializeApplicationEventsResolver()
|
||||
// {
|
||||
// //create an empty resolver so we can add our own custom ones (don't type find)
|
||||
// ApplicationEventsResolver.Current = new ApplicationEventsResolver(
|
||||
// new ActivatorServiceProvider(), Mock.Of<ILogger>(),
|
||||
// new Type[]
|
||||
// {
|
||||
// typeof(LegacyStartupHandler),
|
||||
// typeof(TestApplicationEventHandler)
|
||||
// })
|
||||
// {
|
||||
// CanResolveBeforeFrozen = true
|
||||
// };
|
||||
// }
|
||||
|
||||
public LegacyStartupHandler()
|
||||
{
|
||||
Initialized = true;
|
||||
}
|
||||
}
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// test event handler
|
||||
/// </summary>
|
||||
public class TestApplicationEventHandler : IApplicationEventHandler
|
||||
{
|
||||
public static bool Initialized = false;
|
||||
public static bool Starting = false;
|
||||
public static bool Started = false;
|
||||
// /// <summary>
|
||||
// /// test event handler
|
||||
// /// </summary>
|
||||
// public class TestApplicationEventHandler : IApplicationEventHandler
|
||||
// {
|
||||
// public static bool Initialized = false;
|
||||
// public static bool Starting = false;
|
||||
// public static bool Started = false;
|
||||
|
||||
public void OnApplicationInitialized(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
|
||||
{
|
||||
Initialized = true;
|
||||
}
|
||||
// public void OnApplicationInitialized(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
|
||||
// {
|
||||
// Initialized = true;
|
||||
// }
|
||||
|
||||
public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
|
||||
{
|
||||
Starting = true;
|
||||
}
|
||||
// public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
|
||||
// {
|
||||
// Starting = true;
|
||||
// }
|
||||
|
||||
public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
|
||||
{
|
||||
Started = true;
|
||||
}
|
||||
}
|
||||
// public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
|
||||
// {
|
||||
// Started = true;
|
||||
// }
|
||||
// }
|
||||
|
||||
[Test]
|
||||
public void Handle_IApplicationEventHandler_Objects_Outside_Web_Context()
|
||||
{
|
||||
_testApp.StartApplication(_testApp, new EventArgs());
|
||||
// [Test]
|
||||
// public void Handle_IApplicationEventHandler_Objects_Outside_Web_Context()
|
||||
// {
|
||||
// _testApp.StartApplication(_testApp, new EventArgs());
|
||||
|
||||
Assert.IsTrue(TestApplicationEventHandler.Initialized);
|
||||
Assert.IsTrue(TestApplicationEventHandler.Starting);
|
||||
Assert.IsTrue(TestApplicationEventHandler.Started);
|
||||
}
|
||||
// Assert.IsTrue(TestApplicationEventHandler.Initialized);
|
||||
// Assert.IsTrue(TestApplicationEventHandler.Starting);
|
||||
// Assert.IsTrue(TestApplicationEventHandler.Started);
|
||||
// }
|
||||
|
||||
[Test]
|
||||
public void Ensure_Legacy_Startup_Handlers_Not_Started_Until_Complete()
|
||||
{
|
||||
EventHandler starting = (sender, args) =>
|
||||
{
|
||||
Assert.IsTrue(TestApplicationEventHandler.Initialized);
|
||||
Assert.IsTrue(TestApplicationEventHandler.Starting);
|
||||
Assert.IsFalse(LegacyStartupHandler.Initialized);
|
||||
};
|
||||
EventHandler started = (sender, args) =>
|
||||
{
|
||||
Assert.IsTrue(TestApplicationEventHandler.Started);
|
||||
Assert.IsTrue(LegacyStartupHandler.Initialized);
|
||||
};
|
||||
TestApp.ApplicationStarting += starting;
|
||||
TestApp.ApplicationStarted += started;
|
||||
// [Test]
|
||||
// public void Ensure_Legacy_Startup_Handlers_Not_Started_Until_Complete()
|
||||
// {
|
||||
// EventHandler starting = (sender, args) =>
|
||||
// {
|
||||
// Assert.IsTrue(TestApplicationEventHandler.Initialized);
|
||||
// Assert.IsTrue(TestApplicationEventHandler.Starting);
|
||||
// };
|
||||
// EventHandler started = (sender, args) =>
|
||||
// {
|
||||
// Assert.IsTrue(TestApplicationEventHandler.Started);
|
||||
// };
|
||||
// _testApp.ApplicationStarting += starting;
|
||||
// _testApp.ApplicationStarted += started;
|
||||
|
||||
_testApp.StartApplication(_testApp, new EventArgs());
|
||||
// _testApp.StartApplication(_testApp, new EventArgs());
|
||||
|
||||
TestApp.ApplicationStarting -= starting;
|
||||
TestApp.ApplicationStarting -= started;
|
||||
// _testApp.ApplicationStarting -= starting;
|
||||
// _testApp.ApplicationStarting -= started;
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web.Routing;
|
||||
|
||||
@@ -20,7 +22,7 @@ namespace Umbraco.Tests.Routing
|
||||
var routingContext = GetRoutingContext(urlAsString);
|
||||
var url = routingContext.UmbracoContext.CleanedUmbracoUrl; //very important to use the cleaned up umbraco url
|
||||
var docRequest = new PublishedContentRequest(url, routingContext);
|
||||
var lookup = new ContentFinderByUrlAlias();
|
||||
var lookup = new ContentFinderByUrlAlias(Logger);
|
||||
|
||||
var result = lookup.TryFindContent(docRequest);
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System.Linq;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web.Routing;
|
||||
using umbraco.cms.businesslogic.language;
|
||||
@@ -71,7 +73,7 @@ namespace Umbraco.Tests.Routing
|
||||
if (expectedNode > 0)
|
||||
Assert.AreEqual(expectedCulture, pcr.Culture.Name);
|
||||
|
||||
var finder = new ContentFinderByUrlAlias();
|
||||
var finder = new ContentFinderByUrlAlias(Logger);
|
||||
var result = finder.TryFindContent(pcr);
|
||||
|
||||
if (expectedNode > 0)
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web.Routing;
|
||||
using umbraco.BusinessLogic;
|
||||
@@ -17,7 +19,7 @@ namespace Umbraco.Tests.Routing
|
||||
var routingContext = GetRoutingContext(urlAsString);
|
||||
var url = routingContext.UmbracoContext.CleanedUmbracoUrl; //very important to use the cleaned up umbraco url
|
||||
var docRequest = new PublishedContentRequest(url, routingContext);
|
||||
var lookup = new ContentFinderByIdPath();
|
||||
var lookup = new ContentFinderByIdPath(Logger);
|
||||
|
||||
|
||||
var result = lookup.TryFindContent(docRequest);
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web.Routing;
|
||||
using umbraco.BusinessLogic;
|
||||
@@ -30,7 +32,7 @@ namespace Umbraco.Tests.Routing
|
||||
var routingContext = GetRoutingContext(urlAsString, template);
|
||||
var url = routingContext.UmbracoContext.CleanedUmbracoUrl; //very important to use the cleaned up umbraco url
|
||||
var docRequest = new PublishedContentRequest(url, routingContext);
|
||||
var lookup = new ContentFinderByNiceUrlAndTemplate();
|
||||
var lookup = new ContentFinderByNiceUrlAndTemplate(Logger);
|
||||
|
||||
SettingsForTests.HideTopLevelNodeFromPath = false;
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web.PublishedCache.XmlPublishedCache;
|
||||
using Umbraco.Web.Routing;
|
||||
@@ -30,7 +32,7 @@ namespace Umbraco.Tests.Routing
|
||||
var routingContext = GetRoutingContext(urlString);
|
||||
var url = routingContext.UmbracoContext.CleanedUmbracoUrl; //very important to use the cleaned up umbraco url
|
||||
var docreq = new PublishedContentRequest(url, routingContext);
|
||||
var lookup = new ContentFinderByNiceUrl();
|
||||
var lookup = new ContentFinderByNiceUrl(Logger);
|
||||
SettingsForTests.HideTopLevelNodeFromPath = true;
|
||||
|
||||
var result = lookup.TryFindContent(docreq);
|
||||
@@ -56,8 +58,8 @@ namespace Umbraco.Tests.Routing
|
||||
{
|
||||
var routingContext = GetRoutingContext(urlString);
|
||||
var url = routingContext.UmbracoContext.CleanedUmbracoUrl; //very important to use the cleaned up umbraco url
|
||||
var docreq = new PublishedContentRequest(url, routingContext);
|
||||
var lookup = new ContentFinderByNiceUrl();
|
||||
var docreq = new PublishedContentRequest(url, routingContext);
|
||||
var lookup = new ContentFinderByNiceUrl(Logger);
|
||||
SettingsForTests.HideTopLevelNodeFromPath = false;
|
||||
|
||||
var result = lookup.TryFindContent(docreq);
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web.Routing;
|
||||
using umbraco.cms.businesslogic.web;
|
||||
@@ -160,7 +162,7 @@ namespace Umbraco.Tests.Routing
|
||||
// must lookup domain else lookup by url fails
|
||||
pcr.Engine.FindDomain();
|
||||
|
||||
var lookup = new ContentFinderByNiceUrl();
|
||||
var lookup = new ContentFinderByNiceUrl(Logger);
|
||||
var result = lookup.TryFindContent(pcr);
|
||||
Assert.IsTrue(result);
|
||||
Assert.AreEqual(expectedId, pcr.PublishedContent.Id);
|
||||
@@ -199,7 +201,7 @@ namespace Umbraco.Tests.Routing
|
||||
pcr.Engine.FindDomain();
|
||||
Assert.AreEqual(expectedCulture, pcr.Culture.Name);
|
||||
|
||||
var lookup = new ContentFinderByNiceUrl();
|
||||
var lookup = new ContentFinderByNiceUrl(Logger);
|
||||
var result = lookup.TryFindContent(pcr);
|
||||
Assert.IsTrue(result);
|
||||
Assert.AreEqual(expectedId, pcr.PublishedContent.Id);
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web.Routing;
|
||||
using umbraco.cms.businesslogic.web;
|
||||
@@ -181,8 +183,8 @@ namespace Umbraco.Tests.Routing
|
||||
|
||||
Assert.AreEqual(expectedCulture, pcr.Culture.Name);
|
||||
|
||||
SettingsForTests.HideTopLevelNodeFromPath = false;
|
||||
var finder = new ContentFinderByNiceUrl();
|
||||
SettingsForTests.HideTopLevelNodeFromPath = false;
|
||||
var finder = new ContentFinderByNiceUrl(Logger);
|
||||
var result = finder.TryFindContent(pcr);
|
||||
|
||||
Assert.IsTrue(result);
|
||||
@@ -225,7 +227,7 @@ namespace Umbraco.Tests.Routing
|
||||
|
||||
// find document
|
||||
SettingsForTests.HideTopLevelNodeFromPath = false;
|
||||
var finder = new ContentFinderByNiceUrl();
|
||||
var finder = new ContentFinderByNiceUrl(Logger);
|
||||
var result = finder.TryFindContent(pcr);
|
||||
|
||||
// apply wildcard domain
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Linq;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web.PublishedCache.XmlPublishedCache;
|
||||
using umbraco.cms.businesslogic.web;
|
||||
@@ -52,7 +53,7 @@ namespace Umbraco.Tests.Routing
|
||||
Assert.IsTrue(pcr.HasDomain);
|
||||
|
||||
// check that it's been routed
|
||||
var lookup = new ContentFinderByNiceUrl();
|
||||
var lookup = new ContentFinderByNiceUrl(Logger);
|
||||
var result = lookup.TryFindContent(pcr);
|
||||
Assert.IsTrue(result);
|
||||
Assert.AreEqual(100111, pcr.PublishedContent.Id);
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace Umbraco.Tests.Strings
|
||||
[TestCase("WhoIsNumber6InTheVillage", "Who Is Number6 In The Village")] // issue is fixed
|
||||
public void CompatibleDefaultReplacement(string input, string expected)
|
||||
{
|
||||
var helper = new DefaultShortStringHelper();
|
||||
var helper = new DefaultShortStringHelper(SettingsForTests.GetDefault());
|
||||
var output = input.Length < 2 ? input : helper.SplitPascalCasing(input, ' ').ToFirstUpperInvariant();
|
||||
Assert.AreEqual(expected, output);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Umbraco.Tests.Strings
|
||||
// NOTE pre-filters runs _before_ Recode takes place
|
||||
// so there still may be utf8 chars even though you want ascii
|
||||
|
||||
_helper = new DefaultShortStringHelper()
|
||||
_helper = new DefaultShortStringHelper(SettingsForTests.GetDefault())
|
||||
.WithConfig(CleanStringType.FileName, new DefaultShortStringHelper.Config
|
||||
{
|
||||
//PreFilter = ClearFileChars, // done in IsTerm
|
||||
@@ -131,11 +131,11 @@ namespace Umbraco.Tests.Strings
|
||||
|
||||
const string input = "ÆØÅ and æøå and 中文测试 and אודות האתר and größer БбДдЖж page";
|
||||
|
||||
var helper = new DefaultShortStringHelper().WithDefaultConfig(); // unicode
|
||||
var helper = new DefaultShortStringHelper(settings).WithDefaultConfig(); // unicode
|
||||
var output = helper.CleanStringForUrlSegment(input);
|
||||
Assert.AreEqual("æøå-and-æøå-and-中文测试-and-אודות-האתר-and-größer-ббдджж-page", output);
|
||||
|
||||
helper = new DefaultShortStringHelper()
|
||||
helper = new DefaultShortStringHelper(settings)
|
||||
.WithConfig(CleanStringType.UrlSegment, new DefaultShortStringHelper.Config
|
||||
{
|
||||
IsTerm = (c, leading) => char.IsLetterOrDigit(c) || c == '_',
|
||||
@@ -149,7 +149,7 @@ namespace Umbraco.Tests.Strings
|
||||
[Test]
|
||||
public void CleanStringUnderscoreInTerm()
|
||||
{
|
||||
var helper = new DefaultShortStringHelper()
|
||||
var helper = new DefaultShortStringHelper(SettingsForTests.GetDefault())
|
||||
.WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config
|
||||
{
|
||||
// underscore is accepted within terms
|
||||
@@ -159,7 +159,7 @@ namespace Umbraco.Tests.Strings
|
||||
});
|
||||
Assert.AreEqual("foo_bar*nil", helper.CleanString("foo_bar nil", CleanStringType.Alias));
|
||||
|
||||
helper = new DefaultShortStringHelper()
|
||||
helper = new DefaultShortStringHelper(SettingsForTests.GetDefault())
|
||||
.WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config
|
||||
{
|
||||
// underscore is not accepted within terms
|
||||
@@ -173,7 +173,7 @@ namespace Umbraco.Tests.Strings
|
||||
[Test]
|
||||
public void CleanStringLeadingChars()
|
||||
{
|
||||
var helper = new DefaultShortStringHelper()
|
||||
var helper = new DefaultShortStringHelper(SettingsForTests.GetDefault())
|
||||
.WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config
|
||||
{
|
||||
// letters and digits are valid leading chars
|
||||
@@ -183,7 +183,7 @@ namespace Umbraco.Tests.Strings
|
||||
});
|
||||
Assert.AreEqual("0123foo*bar*543*nil*321", helper.CleanString("0123foo_bar 543 nil 321", CleanStringType.Alias));
|
||||
|
||||
helper = new DefaultShortStringHelper()
|
||||
helper = new DefaultShortStringHelper(SettingsForTests.GetDefault())
|
||||
.WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config
|
||||
{
|
||||
// only letters are valid leading chars
|
||||
@@ -194,14 +194,14 @@ namespace Umbraco.Tests.Strings
|
||||
Assert.AreEqual("foo*bar*543*nil*321", helper.CleanString("0123foo_bar 543 nil 321", CleanStringType.Alias));
|
||||
Assert.AreEqual("foo*bar*543*nil*321", helper.CleanString("0123 foo_bar 543 nil 321", CleanStringType.Alias));
|
||||
|
||||
helper = new DefaultShortStringHelper().WithDefaultConfig();
|
||||
helper = new DefaultShortStringHelper(SettingsForTests.GetDefault()).WithDefaultConfig();
|
||||
Assert.AreEqual("child2", helper.CleanStringForSafeAlias("1child2"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CleanStringTermOnUpper()
|
||||
{
|
||||
var helper = new DefaultShortStringHelper()
|
||||
var helper = new DefaultShortStringHelper(SettingsForTests.GetDefault())
|
||||
.WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config
|
||||
{
|
||||
StringType = CleanStringType.Utf8 | CleanStringType.Unchanged,
|
||||
@@ -211,7 +211,7 @@ namespace Umbraco.Tests.Strings
|
||||
});
|
||||
Assert.AreEqual("foo*Bar", helper.CleanString("fooBar", CleanStringType.Alias));
|
||||
|
||||
helper = new DefaultShortStringHelper()
|
||||
helper = new DefaultShortStringHelper(SettingsForTests.GetDefault())
|
||||
.WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config
|
||||
{
|
||||
StringType = CleanStringType.Utf8 | CleanStringType.Unchanged,
|
||||
@@ -225,7 +225,7 @@ namespace Umbraco.Tests.Strings
|
||||
[Test]
|
||||
public void CleanStringAcronymOnNonUpper()
|
||||
{
|
||||
var helper = new DefaultShortStringHelper()
|
||||
var helper = new DefaultShortStringHelper(SettingsForTests.GetDefault())
|
||||
.WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config
|
||||
{
|
||||
StringType = CleanStringType.Utf8 | CleanStringType.Unchanged,
|
||||
@@ -238,7 +238,7 @@ namespace Umbraco.Tests.Strings
|
||||
Assert.AreEqual("foo*BAnil", helper.CleanString("foo BAnil", CleanStringType.Alias));
|
||||
Assert.AreEqual("foo*Bnil", helper.CleanString("foo Bnil", CleanStringType.Alias));
|
||||
|
||||
helper = new DefaultShortStringHelper()
|
||||
helper = new DefaultShortStringHelper(SettingsForTests.GetDefault())
|
||||
.WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config
|
||||
{
|
||||
StringType = CleanStringType.Utf8 | CleanStringType.Unchanged,
|
||||
@@ -255,7 +255,7 @@ namespace Umbraco.Tests.Strings
|
||||
[Test]
|
||||
public void CleanStringGreedyAcronyms()
|
||||
{
|
||||
var helper = new DefaultShortStringHelper()
|
||||
var helper = new DefaultShortStringHelper(SettingsForTests.GetDefault())
|
||||
.WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config
|
||||
{
|
||||
StringType = CleanStringType.Utf8 | CleanStringType.Unchanged,
|
||||
@@ -268,7 +268,7 @@ namespace Umbraco.Tests.Strings
|
||||
Assert.AreEqual("foo*BA*nil", helper.CleanString("foo BAnil", CleanStringType.Alias));
|
||||
Assert.AreEqual("foo*Bnil", helper.CleanString("foo Bnil", CleanStringType.Alias));
|
||||
|
||||
helper = new DefaultShortStringHelper()
|
||||
helper = new DefaultShortStringHelper(SettingsForTests.GetDefault())
|
||||
.WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config
|
||||
{
|
||||
StringType = CleanStringType.Utf8 | CleanStringType.Unchanged,
|
||||
@@ -285,7 +285,7 @@ namespace Umbraco.Tests.Strings
|
||||
[Test]
|
||||
public void CleanStringWhiteSpace()
|
||||
{
|
||||
var helper = new DefaultShortStringHelper()
|
||||
var helper = new DefaultShortStringHelper(SettingsForTests.GetDefault())
|
||||
.WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config
|
||||
{
|
||||
StringType = CleanStringType.Utf8 | CleanStringType.Unchanged,
|
||||
@@ -298,7 +298,7 @@ namespace Umbraco.Tests.Strings
|
||||
[Test]
|
||||
public void CleanStringSeparator()
|
||||
{
|
||||
var helper = new DefaultShortStringHelper()
|
||||
var helper = new DefaultShortStringHelper(SettingsForTests.GetDefault())
|
||||
.WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config
|
||||
{
|
||||
StringType = CleanStringType.Utf8 | CleanStringType.Unchanged,
|
||||
@@ -306,7 +306,7 @@ namespace Umbraco.Tests.Strings
|
||||
});
|
||||
Assert.AreEqual("foo*bar", helper.CleanString("foo bar", CleanStringType.Alias));
|
||||
|
||||
helper = new DefaultShortStringHelper()
|
||||
helper = new DefaultShortStringHelper(SettingsForTests.GetDefault())
|
||||
.WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config
|
||||
{
|
||||
StringType = CleanStringType.Utf8 | CleanStringType.Unchanged,
|
||||
@@ -314,14 +314,14 @@ namespace Umbraco.Tests.Strings
|
||||
});
|
||||
Assert.AreEqual("foo bar", helper.CleanString("foo bar", CleanStringType.Alias));
|
||||
|
||||
helper = new DefaultShortStringHelper()
|
||||
helper = new DefaultShortStringHelper(SettingsForTests.GetDefault())
|
||||
.WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config
|
||||
{
|
||||
StringType = CleanStringType.Utf8 | CleanStringType.Unchanged
|
||||
});
|
||||
Assert.AreEqual("foobar", helper.CleanString("foo bar", CleanStringType.Alias));
|
||||
|
||||
helper = new DefaultShortStringHelper()
|
||||
helper = new DefaultShortStringHelper(SettingsForTests.GetDefault())
|
||||
.WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config
|
||||
{
|
||||
StringType = CleanStringType.Utf8 | CleanStringType.Unchanged,
|
||||
@@ -333,7 +333,7 @@ namespace Umbraco.Tests.Strings
|
||||
[Test]
|
||||
public void CleanStringSymbols()
|
||||
{
|
||||
var helper = new DefaultShortStringHelper()
|
||||
var helper = new DefaultShortStringHelper(SettingsForTests.GetDefault())
|
||||
.WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config
|
||||
{
|
||||
StringType = CleanStringType.Utf8 | CleanStringType.Unchanged,
|
||||
@@ -387,7 +387,7 @@ namespace Umbraco.Tests.Strings
|
||||
[Test]
|
||||
public void CleanStringEncoding()
|
||||
{
|
||||
var helper = new DefaultShortStringHelper()
|
||||
var helper = new DefaultShortStringHelper(SettingsForTests.GetDefault())
|
||||
.WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config
|
||||
{
|
||||
StringType = CleanStringType.Utf8 | CleanStringType.Unchanged,
|
||||
@@ -396,7 +396,7 @@ namespace Umbraco.Tests.Strings
|
||||
Assert.AreEqual("中文测试", helper.CleanString("中文测试", CleanStringType.Alias));
|
||||
Assert.AreEqual("léger*中文测试*ZÔRG", helper.CleanString("léger 中文测试 ZÔRG", CleanStringType.Alias));
|
||||
|
||||
helper = new DefaultShortStringHelper()
|
||||
helper = new DefaultShortStringHelper(SettingsForTests.GetDefault())
|
||||
.WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config
|
||||
{
|
||||
StringType = CleanStringType.Ascii | CleanStringType.Unchanged,
|
||||
@@ -415,7 +415,7 @@ namespace Umbraco.Tests.Strings
|
||||
contentMock.Setup(x => x.ConvertUrlsToAscii).Returns(false);
|
||||
SettingsForTests.ConfigureSettings(settings);
|
||||
|
||||
var helper = new DefaultShortStringHelper().WithDefaultConfig();
|
||||
var helper = new DefaultShortStringHelper(SettingsForTests.GetDefault()).WithDefaultConfig();
|
||||
|
||||
const string input = "0123 中文测试 中文测试 léger ZÔRG (2) a?? *x";
|
||||
|
||||
@@ -436,7 +436,7 @@ namespace Umbraco.Tests.Strings
|
||||
[Test]
|
||||
public void CleanStringCasing()
|
||||
{
|
||||
var helper = new DefaultShortStringHelper()
|
||||
var helper = new DefaultShortStringHelper(SettingsForTests.GetDefault())
|
||||
.WithConfig(CleanStringType.Alias, new DefaultShortStringHelper.Config
|
||||
{
|
||||
StringType = CleanStringType.Utf8 | CleanStringType.Unchanged,
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Umbraco.Tests.UmbracoExamine
|
||||
{
|
||||
UmbracoExamineSearcher.DisableInitializationCheck = true;
|
||||
BaseUmbracoIndexer.DisableInitializationCheck = true;
|
||||
ShortStringHelperResolver.Current = new ShortStringHelperResolver(new DefaultShortStringHelper());
|
||||
ShortStringHelperResolver.Current = new ShortStringHelperResolver(new DefaultShortStringHelper(SettingsForTests.GetDefault()));
|
||||
|
||||
Resolution.Freeze();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Mvc;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.LightInject;
|
||||
|
||||
namespace Umbraco.Web.LightInject
|
||||
{
|
||||
internal static class LightInjectExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers all IControllers using the PluginManager for scanning and caching found instances for the calling assembly
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
/// <param name="pluginManager"></param>
|
||||
public static void RegisterMvcControllers(this IServiceRegistry container, PluginManager pluginManager)
|
||||
{
|
||||
var types = pluginManager.ResolveTypes<IController>(specificAssemblies: new[] { Assembly.GetCallingAssembly() });
|
||||
foreach (var type in types)
|
||||
{
|
||||
container.Register(type, new PerRequestLifeTime());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers all IHttpController using the PluginManager for scanning and caching found instances for the calling assembly
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
/// <param name="pluginManager"></param>
|
||||
public static void RegisterApiControllers(this IServiceRegistry container, PluginManager pluginManager)
|
||||
{
|
||||
var types = pluginManager.ResolveTypes<IHttpController>(specificAssemblies: new[] { Assembly.GetCallingAssembly() });
|
||||
foreach (var type in types)
|
||||
{
|
||||
container.Register(type, new PerRequestLifeTime());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
/*****************************************************************************
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 bernhard.richter@gmail.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************
|
||||
LightInject.Mvc version 1.0.0.4
|
||||
http://seesharper.github.io/LightInject/
|
||||
http://twitter.com/bernhardrichter
|
||||
******************************************************************************/
|
||||
|
||||
using Umbraco.Core.LightInject;
|
||||
|
||||
[module: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1126:PrefixCallsCorrectly", Justification = "Reviewed")]
|
||||
[module: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1101:PrefixLocalCallsWithThis", Justification = "No inheritance")]
|
||||
[module: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:FileMayOnlyContainASingleClass", Justification = "Single source file deployment.")]
|
||||
[module: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1403:FileMayOnlyContainASingleNamespace", Justification = "Extension methods must be visible")]
|
||||
[module: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1633:FileMustHaveHeader", Justification = "Custom header.")]
|
||||
[module: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented", Justification = "All public members are documented.")]
|
||||
|
||||
namespace Umbraco.Web.LightInject
|
||||
{
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Web.Mvc;
|
||||
using LightInject.Mvc;
|
||||
|
||||
/// <summary>
|
||||
/// Extends the <see cref="IServiceContainer"/> interface with a method that
|
||||
/// enables dependency injection in an ASP.NET MVC application.
|
||||
/// </summary>
|
||||
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
internal static class MvcContainerExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers all <see cref="Controller"/> implementations found in the given <paramref name="assemblies"/>.
|
||||
/// </summary>
|
||||
/// <param name="serviceRegistry">The target <see cref="IServiceRegistry"/>.</param>
|
||||
/// <param name="assemblies">A list of assemblies from which to register <see cref="Controller"/> implementations.</param>
|
||||
public static void RegisterControllers(this IServiceRegistry serviceRegistry, params Assembly[] assemblies)
|
||||
{
|
||||
foreach (var assembly in assemblies)
|
||||
{
|
||||
var controllerTypes =
|
||||
assembly.GetTypes().Where(t => !t.IsAbstract && typeof(IController).IsAssignableFrom(t));
|
||||
foreach (var controllerType in controllerTypes)
|
||||
{
|
||||
serviceRegistry.Register(controllerType, new PerRequestLifeTime());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers all <see cref="Controller"/> implementations found in this assembly.
|
||||
/// </summary>
|
||||
/// <param name="serviceRegistry">The target <see cref="IServiceRegistry"/>.</param>
|
||||
public static void RegisterControllers(this IServiceRegistry serviceRegistry)
|
||||
{
|
||||
RegisterControllers(serviceRegistry, Assembly.GetCallingAssembly());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enables dependency injection in an ASP.NET MVC application.
|
||||
/// </summary>
|
||||
/// <param name="serviceContainer">The target <see cref="IServiceContainer"/>.</param>
|
||||
public static void EnableMvc(this IServiceContainer serviceContainer)
|
||||
{
|
||||
((ServiceContainer)serviceContainer).EnablePerWebRequestScope();
|
||||
SetDependencyResolver(serviceContainer);
|
||||
InitializeFilterAttributeProvider(serviceContainer);
|
||||
}
|
||||
|
||||
private static void SetDependencyResolver(IServiceContainer serviceContainer)
|
||||
{
|
||||
DependencyResolver.SetResolver(new LightInjectMvcDependencyResolver(serviceContainer));
|
||||
}
|
||||
|
||||
private static void InitializeFilterAttributeProvider(IServiceContainer serviceContainer)
|
||||
{
|
||||
RemoveExistingFilterAttributeFilterProviders();
|
||||
var filterProvider = new LightInjectFilterProvider(serviceContainer);
|
||||
FilterProviders.Providers.Add(filterProvider);
|
||||
}
|
||||
|
||||
private static void RemoveExistingFilterAttributeFilterProviders()
|
||||
{
|
||||
var existingFilterAttributeProviders =
|
||||
FilterProviders.Providers.OfType<FilterAttributeFilterProvider>().ToArray();
|
||||
foreach (FilterAttributeFilterProvider filterAttributeFilterProvider in existingFilterAttributeProviders)
|
||||
{
|
||||
FilterProviders.Providers.Remove(filterAttributeFilterProvider);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace Umbraco.Web.LightInject.Mvc
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
|
||||
/// <summary>
|
||||
/// An <see cref="IDependencyResolver"/> adapter for the LightInject service container.
|
||||
/// </summary>
|
||||
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
internal class LightInjectMvcDependencyResolver : IDependencyResolver
|
||||
{
|
||||
private readonly IServiceContainer serviceContainer;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LightInjectMvcDependencyResolver"/> class.
|
||||
/// </summary>
|
||||
/// <param name="serviceContainer">The <see cref="IServiceContainer"/> instance to
|
||||
/// be used for resolving service instances.</param>
|
||||
internal LightInjectMvcDependencyResolver(IServiceContainer serviceContainer)
|
||||
{
|
||||
this.serviceContainer = serviceContainer;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resolves singly registered services that support arbitrary object creation.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The requested service or object.
|
||||
/// </returns>
|
||||
/// <param name="serviceType">The type of the requested service or object.</param>
|
||||
public object GetService(Type serviceType)
|
||||
{
|
||||
return serviceContainer.TryGetInstance(serviceType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resolves multiply registered services.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The requested services.
|
||||
/// </returns>
|
||||
/// <param name="serviceType">The type of the requested services.</param>
|
||||
public IEnumerable<object> GetServices(Type serviceType)
|
||||
{
|
||||
return serviceContainer.GetAllInstances(serviceType);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="FilterAttributeFilterProvider"/> that uses an <see cref="IServiceContainer"/>
|
||||
/// to inject property dependencies into <see cref="Filter"/> instances.
|
||||
/// </summary>
|
||||
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
internal class LightInjectFilterProvider : FilterAttributeFilterProvider
|
||||
{
|
||||
private readonly IServiceContainer serviceContainer;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LightInjectFilterProvider"/> class.
|
||||
/// </summary>
|
||||
/// <param name="serviceContainer">The <see cref="IServiceContainer"/> instance
|
||||
/// used to inject property dependencies.</param>
|
||||
public LightInjectFilterProvider(IServiceContainer serviceContainer)
|
||||
{
|
||||
this.serviceContainer = serviceContainer;
|
||||
serviceContainer.RegisterInstance<IFilterProvider>(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggregates the filters from all of the filter providers into one collection.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The collection filters from all of the filter providers.
|
||||
/// </returns>
|
||||
/// <param name="controllerContext">The controller context.</param>
|
||||
/// <param name="actionDescriptor">The action descriptor.</param>
|
||||
public override IEnumerable<Filter> GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
|
||||
{
|
||||
var filters = base.GetFilters(controllerContext, actionDescriptor).ToArray();
|
||||
foreach (var filter in filters)
|
||||
{
|
||||
serviceContainer.InjectProperties(filter.Instance);
|
||||
}
|
||||
|
||||
return filters;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
/*****************************************************************************
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 bernhard.richter@gmail.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************
|
||||
LightInject.Web version 1.0.0.7
|
||||
http://seesharper.github.io/LightInject/
|
||||
http://twitter.com/bernhardrichter
|
||||
******************************************************************************/
|
||||
|
||||
using Umbraco.Core.LightInject;
|
||||
|
||||
[assembly: System.Web.PreApplicationStartMethod(typeof(Umbraco.Web.LightInject.Web.LightInjectHttpModuleInitializer), "Initialize")]
|
||||
[module: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1126:PrefixCallsCorrectly", Justification = "Reviewed")]
|
||||
[module: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1101:PrefixLocalCallsWithThis", Justification = "No inheritance")]
|
||||
[module: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:FileMayOnlyContainASingleClass", Justification = "Single source file deployment.")]
|
||||
[module: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1403:FileMayOnlyContainASingleNamespace", Justification = "Extension methods must be visible")]
|
||||
[module: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1633:FileMustHaveHeader", Justification = "Custom header.")]
|
||||
[module: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented", Justification = "All public members are documented.")]
|
||||
|
||||
namespace Umbraco.Web.LightInject
|
||||
{
|
||||
using Web;
|
||||
|
||||
/// <summary>
|
||||
/// Extends the <see cref="IServiceContainer"/> interface with a method
|
||||
/// to enable services that are scoped per web request.
|
||||
/// </summary>
|
||||
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
internal static class WebContainerExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Ensures that services registered with the <see cref="PerScopeLifetime"/> is properly
|
||||
/// disposed when the web request ends.
|
||||
/// </summary>
|
||||
/// <param name="serviceContainer">The target <see cref="IServiceContainer"/>.</param>
|
||||
public static void EnablePerWebRequestScope(this ServiceContainer serviceContainer)
|
||||
{
|
||||
serviceContainer.ScopeManagerProvider = new PerWebRequestScopeManagerProvider();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace Umbraco.Web.LightInject.Web
|
||||
{
|
||||
using System;
|
||||
using System.Web;
|
||||
using Microsoft.Web.Infrastructure.DynamicModuleHelper;
|
||||
|
||||
/// <summary>
|
||||
/// Registers the <see cref="LightInjectHttpModule"/> with the current <see cref="HttpApplication"/>.
|
||||
/// </summary>
|
||||
public static class LightInjectHttpModuleInitializer
|
||||
{
|
||||
private static bool isInitialized;
|
||||
|
||||
/// <summary>
|
||||
/// Executed before the <see cref="HttpApplication"/> is started and registers
|
||||
/// the <see cref="LightInjectHttpModule"/> with the current <see cref="HttpApplication"/>.
|
||||
/// </summary>
|
||||
public static void Initialize()
|
||||
{
|
||||
if (!isInitialized)
|
||||
{
|
||||
isInitialized = true;
|
||||
DynamicModuleUtility.RegisterModule(typeof(LightInjectHttpModule));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="IHttpModule"/> that ensures that services registered
|
||||
/// with the <see cref="PerScopeLifetime"/> lifetime is scoped per web request.
|
||||
/// </summary>
|
||||
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
public class LightInjectHttpModule : IHttpModule
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a module and prepares it to handle requests.
|
||||
/// </summary>
|
||||
/// <param name="context">An <see cref="HttpApplication"/> that provides access to the methods, properties, and events common to all application objects within an ASP.NET application </param>
|
||||
public void Init(HttpApplication context)
|
||||
{
|
||||
context.BeginRequest += BeginRequest;
|
||||
context.EndRequest += EndRequest;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposes of the resources (other than memory) used by the module that implements <see cref="T:System.Web.IHttpModule"/>.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
private static void EndRequest(object sender, EventArgs eventArgs)
|
||||
{
|
||||
var application = sender as HttpApplication;
|
||||
if (application == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var scopeManager = (ScopeManager)application.Context.Items["ScopeManager"];
|
||||
if (scopeManager != null)
|
||||
{
|
||||
scopeManager.CurrentScope.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private static void BeginRequest(object sender, EventArgs eventArgs)
|
||||
{
|
||||
var application = sender as HttpApplication;
|
||||
if (application == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var scopeManager = new ScopeManager();
|
||||
scopeManager.BeginScope();
|
||||
application.Context.Items["ScopeManager"] = scopeManager;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An <see cref="IScopeManagerProvider"/> that provides the <see cref="ScopeManager"/>
|
||||
/// used by the current <see cref="HttpRequest"/>.
|
||||
/// </summary>
|
||||
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
internal class PerWebRequestScopeManagerProvider : IScopeManagerProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the <see cref="ScopeManager"/> that is responsible for managing scopes.
|
||||
/// </summary>
|
||||
/// <returns>The <see cref="ScopeManager"/> that is responsible for managing scopes.</returns>
|
||||
public ScopeManager GetScopeManager()
|
||||
{
|
||||
var scopeManager = (ScopeManager)HttpContext.Current.Items["ScopeManager"];
|
||||
if (scopeManager == null)
|
||||
{
|
||||
throw new InvalidOperationException("Unable to locate a scope manager for the current HttpRequest. Ensure that the LightInjectHttpModule has been added.");
|
||||
}
|
||||
|
||||
return scopeManager;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,235 @@
|
||||
/*****************************************************************************
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 bernhard.richter@gmail.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************
|
||||
LightInject.WebApi version 1.0.0.3
|
||||
http://www.lightinject.net/
|
||||
http://twitter.com/bernhardrichter
|
||||
******************************************************************************/
|
||||
|
||||
using Umbraco.Core.LightInject;
|
||||
|
||||
[module: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1126:PrefixCallsCorrectly", Justification = "Reviewed")]
|
||||
[module: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1101:PrefixLocalCallsWithThis", Justification = "No inheritance")]
|
||||
[module: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:FileMayOnlyContainASingleClass", Justification = "Single source file deployment.")]
|
||||
[module: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1403:FileMayOnlyContainASingleNamespace", Justification = "Extension methods must be visible")]
|
||||
[module: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1633:FileMustHaveHeader", Justification = "Custom header.")]
|
||||
[module: System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented", Justification = "All public members are documented.")]
|
||||
|
||||
namespace Umbraco.Web.LightInject
|
||||
{
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Web.Http;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.Filters;
|
||||
using LightInject.WebApi;
|
||||
|
||||
/// <summary>
|
||||
/// Extends the <see cref="IServiceContainer"/> interface with methods that
|
||||
/// enables dependency injection in a Web API application.
|
||||
/// </summary>
|
||||
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
internal static class WebApiContainerExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Enables dependency injection in a Web API application.
|
||||
/// </summary>
|
||||
/// <param name="serviceContainer">The target <see cref="IServiceContainer"/>.</param>
|
||||
/// <param name="httpConfiguration">The <see cref="HttpConfiguration"/> that represents the configuration of this Web API application.</param>
|
||||
public static void EnableWebApi(this IServiceContainer serviceContainer, HttpConfiguration httpConfiguration)
|
||||
{
|
||||
httpConfiguration.DependencyResolver = new LightInjectWebApiDependencyResolver(serviceContainer);
|
||||
var provider = httpConfiguration.Services.GetFilterProviders();
|
||||
httpConfiguration.Services.RemoveAll(typeof(IFilterProvider), o => true);
|
||||
httpConfiguration.Services.Add(typeof(IFilterProvider), new LightInjectWebApiFilterProvider(serviceContainer, provider));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers all <see cref="ApiController"/> implementations found in the given <paramref name="assemblies"/>.
|
||||
/// </summary>
|
||||
/// <param name="serviceRegistry">The target <see cref="IServiceRegistry"/>.</param>
|
||||
/// <param name="assemblies">A list of assemblies from which to register <see cref="ApiController"/> implementations.</param>
|
||||
public static void RegisterApiControllers(this IServiceRegistry serviceRegistry, params Assembly[] assemblies)
|
||||
{
|
||||
foreach (var assembly in assemblies)
|
||||
{
|
||||
var controllerTypes = assembly.GetTypes().Where(t => !t.IsAbstract && typeof(IHttpController).IsAssignableFrom(t));
|
||||
foreach (var controllerType in controllerTypes)
|
||||
{
|
||||
serviceRegistry.Register(controllerType, new PerRequestLifeTime());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Registers all <see cref="ApiController"/> implementations found in this assembly.
|
||||
/// </summary>
|
||||
/// <param name="serviceRegistry">The target <see cref="IServiceRegistry"/>.</param>
|
||||
public static void RegisterApiControllers(this IServiceRegistry serviceRegistry)
|
||||
{
|
||||
RegisterApiControllers(serviceRegistry, Assembly.GetCallingAssembly());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace Umbraco.Web.LightInject.WebApi
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Http;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.Dependencies;
|
||||
using System.Web.Http.Filters;
|
||||
|
||||
/// <summary>
|
||||
/// An <see cref="IDependencyResolver"/> adapter for the LightInject service container
|
||||
/// that enables <see cref="ApiController"/> instances and their dependencies to be
|
||||
/// resolved through the service container.
|
||||
/// </summary>
|
||||
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
internal class LightInjectWebApiDependencyResolver : IDependencyResolver
|
||||
{
|
||||
private readonly IServiceContainer serviceContainer;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LightInjectWebApiDependencyResolver"/> class.
|
||||
/// </summary>
|
||||
/// <param name="serviceContainer">The <see cref="IServiceContainer"/> instance to
|
||||
/// be used for resolving service instances.</param>
|
||||
internal LightInjectWebApiDependencyResolver(IServiceContainer serviceContainer)
|
||||
{
|
||||
this.serviceContainer = serviceContainer;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposes the underlying <see cref="IServiceContainer"/>.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
serviceContainer.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an instance of the given <paramref name="serviceType"/>.
|
||||
/// </summary>
|
||||
/// <param name="serviceType">The type of the requested service.</param>
|
||||
/// <returns>The requested service instance if available, otherwise null.</returns>
|
||||
public object GetService(Type serviceType)
|
||||
{
|
||||
return serviceContainer.TryGetInstance(serviceType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all instance of the given <paramref name="serviceType"/>.
|
||||
/// </summary>
|
||||
/// <param name="serviceType">The type of services to resolve.</param>
|
||||
/// <returns>A list that contains all implementations of the <paramref name="serviceType"/>.</returns>
|
||||
public IEnumerable<object> GetServices(Type serviceType)
|
||||
{
|
||||
return serviceContainer.GetAllInstances(serviceType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Starts a new <see cref="IDependencyScope"/> that represents
|
||||
/// the scope for services registered with <see cref="PerScopeLifetime"/>.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A new <see cref="IDependencyScope"/>.
|
||||
/// </returns>
|
||||
public IDependencyScope BeginScope()
|
||||
{
|
||||
return new LightInjectWebApiDependencyScope(serviceContainer, serviceContainer.BeginScope());
|
||||
}
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
internal class LightInjectWebApiDependencyScope : IDependencyScope
|
||||
{
|
||||
private readonly IServiceContainer serviceContainer;
|
||||
private readonly Scope scope;
|
||||
|
||||
public LightInjectWebApiDependencyScope(IServiceContainer serviceContainer, Scope scope)
|
||||
{
|
||||
this.serviceContainer = serviceContainer;
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
public object GetService(Type serviceType)
|
||||
{
|
||||
return serviceContainer.GetInstance(serviceType);
|
||||
}
|
||||
|
||||
public IEnumerable<object> GetServices(Type serviceType)
|
||||
{
|
||||
return serviceContainer.GetAllInstances(serviceType);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
scope.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="IFilterProvider"/> that uses an <see cref="IServiceContainer"/>
|
||||
/// to inject property dependencies into <see cref="IFilter"/> instances.
|
||||
/// </summary>
|
||||
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
internal class LightInjectWebApiFilterProvider : IFilterProvider
|
||||
{
|
||||
private readonly IServiceContainer serviceContainer;
|
||||
private readonly IEnumerable<IFilterProvider> filterProviders;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LightInjectWebApiFilterProvider"/> class.
|
||||
/// </summary>
|
||||
/// <param name="serviceContainer">The <see cref="IServiceContainer"/> instance
|
||||
/// used to inject property dependencies.</param>
|
||||
/// <param name="filterProviders">The list of existing filter providers.</param>
|
||||
public LightInjectWebApiFilterProvider(IServiceContainer serviceContainer, IEnumerable<IFilterProvider> filterProviders)
|
||||
{
|
||||
this.serviceContainer = serviceContainer;
|
||||
this.filterProviders = filterProviders;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumeration of filters.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// An enumeration of filters.
|
||||
/// </returns>
|
||||
/// <param name="configuration">The HTTP configuration.</param><param name="actionDescriptor">The action descriptor.</param>
|
||||
public IEnumerable<FilterInfo> GetFilters(HttpConfiguration configuration, HttpActionDescriptor actionDescriptor)
|
||||
{
|
||||
var filters = filterProviders.SelectMany(p => p.GetFilters(configuration, actionDescriptor)).ToArray();
|
||||
|
||||
foreach (var filterInfo in filters)
|
||||
{
|
||||
serviceContainer.InjectProperties(filterInfo.Instance);
|
||||
}
|
||||
|
||||
return filters;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,8 +12,15 @@ namespace Umbraco.Web.Media.ThumbnailProviders
|
||||
{
|
||||
[WeightedPlugin(1000)]
|
||||
public class ImageThumbnailProvider : AbstractThumbnailProvider
|
||||
{
|
||||
protected override IEnumerable<string> SupportedExtensions
|
||||
{
|
||||
private readonly MediaFileSystem _mediaFileSystem;
|
||||
|
||||
public ImageThumbnailProvider(MediaFileSystem mediaFileSystem)
|
||||
{
|
||||
_mediaFileSystem = mediaFileSystem;
|
||||
}
|
||||
|
||||
protected override IEnumerable<string> SupportedExtensions
|
||||
{
|
||||
get { return new List<string> { ".jpeg", ".jpg", ".gif", ".bmp", ".png", ".tiff", ".tif" }; }
|
||||
}
|
||||
@@ -37,7 +44,7 @@ namespace Umbraco.Web.Media.ThumbnailProviders
|
||||
|
||||
try
|
||||
{
|
||||
var fs = FileSystemProviderManager.Current.GetFileSystemProvider<MediaFileSystem>();
|
||||
var fs = _mediaFileSystem;
|
||||
var relativeThumbPath = fs.GetRelativePath(tmpThumbUrl);
|
||||
if (!fs.FileExists(relativeThumbPath))
|
||||
return false;
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.LightInject;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Media;
|
||||
using Umbraco.Core.ObjectResolution;
|
||||
@@ -12,16 +13,16 @@ using umbraco.BusinessLogic.Utils;
|
||||
|
||||
namespace Umbraco.Web.Media.ThumbnailProviders
|
||||
{
|
||||
internal sealed class ThumbnailProvidersResolver : ManyObjectsResolverBase<ThumbnailProvidersResolver, IThumbnailProvider>
|
||||
internal sealed class ThumbnailProvidersResolver : ContainerManyObjectsResolver<ThumbnailProvidersResolver, IThumbnailProvider>
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="serviceProvider"></param>
|
||||
/// <param name="container"></param>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="providers"></param>
|
||||
internal ThumbnailProvidersResolver(IServiceProvider serviceProvider, ILogger logger, IEnumerable<Type> providers)
|
||||
: base(serviceProvider, logger, providers)
|
||||
internal ThumbnailProvidersResolver(IServiceContainer container, ILogger logger, IEnumerable<Type> providers)
|
||||
: base(container, logger, providers)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -33,21 +33,6 @@ namespace Umbraco.Web.Mvc
|
||||
return Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an instance of the default controller instance.
|
||||
/// </summary>
|
||||
public IRenderMvcController GetControllerInstance()
|
||||
{
|
||||
//try the dependency resolver, then the activator
|
||||
var instance = DependencyResolver.Current.GetService(Value) ?? Activator.CreateInstance(Value);
|
||||
var result = instance as IRenderMvcController;
|
||||
if (result == null)
|
||||
{
|
||||
throw new InvalidOperationException("Could not create an instance of " + Value + " for the default " + typeof(IRenderMvcController).Name);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the default RenderMvcController type
|
||||
/// </summary>
|
||||
|
||||
@@ -1,13 +1,27 @@
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
using Umbraco.Core.LightInject;
|
||||
using Umbraco.Core.ObjectResolution;
|
||||
|
||||
namespace Umbraco.Web.PublishedCache
|
||||
{
|
||||
//TODO: REmove this requirement, just use normal IoC and publicize IPublishedCaches
|
||||
|
||||
/// <summary>
|
||||
/// Resolves the IPublishedCaches object.
|
||||
/// </summary>
|
||||
internal sealed class PublishedCachesResolver : SingleObjectResolverBase<PublishedCachesResolver, IPublishedCaches>
|
||||
internal sealed class PublishedCachesResolver : ContainerSingleObjectResolver<PublishedCachesResolver, IPublishedCaches>
|
||||
{
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// Initializes the resolver to use IoC
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
/// <param name="implementationType"></param>
|
||||
public PublishedCachesResolver(IServiceContainer container, Type implementationType) : base(container, implementationType)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PublishedCachesResolver"/> class with caches.
|
||||
/// </summary>
|
||||
/// <param name="caches">The caches.</param>
|
||||
@@ -16,7 +30,16 @@ namespace Umbraco.Web.PublishedCache
|
||||
: base(caches)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// Initializes the resolver to use IoC
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
/// <param name="implementationType"></param>
|
||||
public PublishedCachesResolver(IServiceContainer container, Expression<Func<IServiceFactory, IPublishedCaches>> implementationType) : base(container, implementationType)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the caches.
|
||||
/// </summary>
|
||||
/// <param name="caches">The caches.</param>
|
||||
|
||||
@@ -22,6 +22,10 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
{
|
||||
internal class PublishedContentCache : IPublishedContentCache
|
||||
{
|
||||
public PublishedContentCache()
|
||||
{
|
||||
}
|
||||
|
||||
#region Routes cache
|
||||
|
||||
private readonly RoutesCache _routesCache = new RoutesCache(!UnitTesting);
|
||||
|
||||
@@ -13,7 +13,14 @@ namespace Umbraco.Web.Routing
|
||||
/// </remarks>
|
||||
public class ContentFinderByIdPath : IContentFinder
|
||||
{
|
||||
/// <summary>
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public ContentFinderByIdPath(ILogger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to find and assign an Umbraco document to a <c>PublishedContentRequest</c>.
|
||||
/// </summary>
|
||||
/// <param name="docRequest">The <c>PublishedContentRequest</c>.</param>
|
||||
@@ -33,13 +40,13 @@ namespace Umbraco.Web.Routing
|
||||
|
||||
if (nodeId > 0)
|
||||
{
|
||||
LogHelper.Debug<ContentFinderByIdPath>("Id={0}", () => nodeId);
|
||||
_logger.Debug<ContentFinderByIdPath>("Id={0}", () => nodeId);
|
||||
node = docRequest.RoutingContext.UmbracoContext.ContentCache.GetById(nodeId);
|
||||
|
||||
if (node != null)
|
||||
{
|
||||
docRequest.PublishedContent = node;
|
||||
LogHelper.Debug<ContentFinderByIdPath>("Found node with id={0}", () => docRequest.PublishedContent.Id);
|
||||
_logger.Debug<ContentFinderByIdPath>("Found node with id={0}", () => docRequest.PublishedContent.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -49,7 +56,7 @@ namespace Umbraco.Web.Routing
|
||||
}
|
||||
|
||||
if (nodeId == -1)
|
||||
LogHelper.Debug<ContentFinderByIdPath>("Not a node id");
|
||||
_logger.Debug<ContentFinderByIdPath>("Not a node id");
|
||||
|
||||
return node != null;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,13 @@ namespace Umbraco.Web.Routing
|
||||
/// </summary>
|
||||
public class ContentFinderByLegacy404 : IContentFinder
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public ContentFinderByLegacy404(ILogger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to find and assign an Umbraco document to a <c>PublishedContentRequest</c>.
|
||||
/// </summary>
|
||||
@@ -15,7 +22,7 @@ namespace Umbraco.Web.Routing
|
||||
/// <returns>A value indicating whether an Umbraco document was found and assigned.</returns>
|
||||
public bool TryFindContent(PublishedContentRequest pcr)
|
||||
{
|
||||
LogHelper.Debug<ContentFinderByLegacy404>("Looking for a page to handle 404.");
|
||||
_logger.Debug<ContentFinderByLegacy404>("Looking for a page to handle 404.");
|
||||
|
||||
// TODO - replace the whole logic and stop calling into library!
|
||||
var error404 = global::umbraco.library.GetCurrentNotFoundPageId();
|
||||
@@ -25,17 +32,17 @@ namespace Umbraco.Web.Routing
|
||||
|
||||
if (id > 0)
|
||||
{
|
||||
LogHelper.Debug<ContentFinderByLegacy404>("Got id={0}.", () => id);
|
||||
_logger.Debug<ContentFinderByLegacy404>("Got id={0}.", () => id);
|
||||
|
||||
content = pcr.RoutingContext.UmbracoContext.ContentCache.GetById(id);
|
||||
|
||||
LogHelper.Debug<ContentFinderByLegacy404>(content == null
|
||||
_logger.Debug<ContentFinderByLegacy404>(content == null
|
||||
? "Could not find content with that id."
|
||||
: "Found corresponding content.");
|
||||
}
|
||||
else
|
||||
{
|
||||
LogHelper.Debug<ContentFinderByLegacy404>("Got nothing.");
|
||||
_logger.Debug<ContentFinderByLegacy404>("Got nothing.");
|
||||
}
|
||||
|
||||
pcr.PublishedContent = content;
|
||||
|
||||
@@ -12,6 +12,13 @@ namespace Umbraco.Web.Routing
|
||||
/// </remarks>
|
||||
public class ContentFinderByNiceUrl : IContentFinder
|
||||
{
|
||||
protected ILogger Logger { get; private set; }
|
||||
|
||||
public ContentFinderByNiceUrl(ILogger logger)
|
||||
{
|
||||
Logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to find and assign an Umbraco document to a <c>PublishedContentRequest</c>.
|
||||
/// </summary>
|
||||
@@ -21,7 +28,7 @@ namespace Umbraco.Web.Routing
|
||||
{
|
||||
string route;
|
||||
if (docRequest.HasDomain)
|
||||
route = docRequest.Domain.RootNodeId.ToString() + DomainHelper.PathRelativeToDomain(docRequest.DomainUri, docRequest.Uri.GetAbsolutePathDecoded());
|
||||
route = docRequest.Domain.RootNodeId + DomainHelper.PathRelativeToDomain(docRequest.DomainUri, docRequest.Uri.GetAbsolutePathDecoded());
|
||||
else
|
||||
route = docRequest.Uri.GetAbsolutePathDecoded();
|
||||
|
||||
@@ -37,17 +44,17 @@ namespace Umbraco.Web.Routing
|
||||
/// <returns>The document node, or null.</returns>
|
||||
protected IPublishedContent FindContent(PublishedContentRequest docreq, string route)
|
||||
{
|
||||
LogHelper.Debug<ContentFinderByNiceUrl>("Test route \"{0}\"", () => route);
|
||||
Logger.Debug<ContentFinderByNiceUrl>("Test route \"{0}\"", () => route);
|
||||
|
||||
var node = docreq.RoutingContext.UmbracoContext.ContentCache.GetByRoute(route);
|
||||
if (node != null)
|
||||
{
|
||||
docreq.PublishedContent = node;
|
||||
LogHelper.Debug<ContentFinderByNiceUrl>("Got content, id={0}", () => node.Id);
|
||||
Logger.Debug<ContentFinderByNiceUrl>("Got content, id={0}", () => node.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogHelper.Debug<ContentFinderByNiceUrl>("No match.");
|
||||
Logger.Debug<ContentFinderByNiceUrl>("No match.");
|
||||
}
|
||||
|
||||
return node;
|
||||
|
||||
@@ -4,54 +4,59 @@ using Umbraco.Core;
|
||||
|
||||
namespace Umbraco.Web.Routing
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides an implementation of <see cref="IContentFinder"/> that handles page nice urls and a template.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>Handles <c>/foo/bar/template</c> where <c>/foo/bar</c> is the nice url of a document, and <c>template</c> a template alias.</para>
|
||||
/// <para>If successful, then the template of the document request is also assigned.</para>
|
||||
/// </remarks>
|
||||
/// <summary>
|
||||
/// Provides an implementation of <see cref="IContentFinder"/> that handles page nice urls and a template.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>Handles <c>/foo/bar/template</c> where <c>/foo/bar</c> is the nice url of a document, and <c>template</c> a template alias.</para>
|
||||
/// <para>If successful, then the template of the document request is also assigned.</para>
|
||||
/// </remarks>
|
||||
public class ContentFinderByNiceUrlAndTemplate : ContentFinderByNiceUrl
|
||||
{
|
||||
/// <summary>
|
||||
/// Tries to find and assign an Umbraco document to a <c>PublishedContentRequest</c>.
|
||||
/// </summary>
|
||||
/// <param name="docRequest">The <c>PublishedContentRequest</c>.</param>
|
||||
/// <returns>A value indicating whether an Umbraco document was found and assigned.</returns>
|
||||
/// <remarks>If successful, also assigns the template.</remarks>
|
||||
public override bool TryFindContent(PublishedContentRequest docRequest)
|
||||
public ContentFinderByNiceUrlAndTemplate(ILogger logger)
|
||||
: base(logger)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to find and assign an Umbraco document to a <c>PublishedContentRequest</c>.
|
||||
/// </summary>
|
||||
/// <param name="docRequest">The <c>PublishedContentRequest</c>.</param>
|
||||
/// <returns>A value indicating whether an Umbraco document was found and assigned.</returns>
|
||||
/// <remarks>If successful, also assigns the template.</remarks>
|
||||
public override bool TryFindContent(PublishedContentRequest docRequest)
|
||||
{
|
||||
IPublishedContent node = null;
|
||||
string path = docRequest.Uri.GetAbsolutePathDecoded();
|
||||
string path = docRequest.Uri.GetAbsolutePathDecoded();
|
||||
|
||||
if (docRequest.HasDomain)
|
||||
path = DomainHelper.PathRelativeToDomain(docRequest.DomainUri, path);
|
||||
if (docRequest.HasDomain)
|
||||
path = DomainHelper.PathRelativeToDomain(docRequest.DomainUri, path);
|
||||
|
||||
if (path != "/") // no template if "/"
|
||||
if (path != "/") // no template if "/"
|
||||
{
|
||||
var pos = path.LastIndexOf('/');
|
||||
var templateAlias = path.Substring(pos + 1);
|
||||
path = pos == 0 ? "/" : path.Substring(0, pos);
|
||||
var pos = path.LastIndexOf('/');
|
||||
var templateAlias = path.Substring(pos + 1);
|
||||
path = pos == 0 ? "/" : path.Substring(0, pos);
|
||||
|
||||
var template = ApplicationContext.Current.Services.FileService.GetTemplate(templateAlias);
|
||||
if (template != null)
|
||||
{
|
||||
LogHelper.Debug<ContentFinderByNiceUrlAndTemplate>("Valid template: \"{0}\"", () => templateAlias);
|
||||
Logger.Debug<ContentFinderByNiceUrlAndTemplate>("Valid template: \"{0}\"", () => templateAlias);
|
||||
|
||||
var route = docRequest.HasDomain ? (docRequest.Domain.RootNodeId.ToString() + path) : path;
|
||||
node = FindContent(docRequest, route);
|
||||
var route = docRequest.HasDomain ? (docRequest.Domain.RootNodeId.ToString() + path) : path;
|
||||
node = FindContent(docRequest, route);
|
||||
|
||||
if (node != null)
|
||||
docRequest.TemplateModel = template;
|
||||
docRequest.TemplateModel = template;
|
||||
}
|
||||
else
|
||||
{
|
||||
LogHelper.Debug<ContentFinderByNiceUrlAndTemplate>("Not a valid template: \"{0}\"", () => templateAlias);
|
||||
Logger.Debug<ContentFinderByNiceUrlAndTemplate>("Not a valid template: \"{0}\"", () => templateAlias);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogHelper.Debug<ContentFinderByNiceUrlAndTemplate>("No template in path \"/\"");
|
||||
Logger.Debug<ContentFinderByNiceUrlAndTemplate>("No template in path \"/\"");
|
||||
}
|
||||
|
||||
return node != null;
|
||||
|
||||
@@ -5,56 +5,61 @@ using Umbraco.Core;
|
||||
|
||||
namespace Umbraco.Web.Routing
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides an implementation of <see cref="IContentFinder"/> that handles profiles.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>Handles <c>/profile/login</c> where <c>/profile</c> is the profile page nice url and <c>login</c> the login of a member.</para>
|
||||
/// <para>This should rather be done with a rewriting rule. There would be multiple profile pages in multi-sites/multi-langs setups.
|
||||
/// We keep it for backward compatility reasons.</para>
|
||||
/// </remarks>
|
||||
/// <summary>
|
||||
/// Provides an implementation of <see cref="IContentFinder"/> that handles profiles.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>Handles <c>/profile/login</c> where <c>/profile</c> is the profile page nice url and <c>login</c> the login of a member.</para>
|
||||
/// <para>This should rather be done with a rewriting rule. There would be multiple profile pages in multi-sites/multi-langs setups.
|
||||
/// We keep it for backward compatility reasons.</para>
|
||||
/// </remarks>
|
||||
public class ContentFinderByProfile : ContentFinderByNiceUrl
|
||||
{
|
||||
/// <summary>
|
||||
/// Tries to find and assign an Umbraco document to a <c>PublishedContentRequest</c>.
|
||||
/// </summary>
|
||||
/// <param name="docRequest">The <c>PublishedContentRequest</c>.</param>
|
||||
/// <returns>A value indicating whether an Umbraco document was found and assigned.</returns>
|
||||
public override bool TryFindContent(PublishedContentRequest docRequest)
|
||||
public ContentFinderByProfile(ILogger logger)
|
||||
: base(logger)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to find and assign an Umbraco document to a <c>PublishedContentRequest</c>.
|
||||
/// </summary>
|
||||
/// <param name="docRequest">The <c>PublishedContentRequest</c>.</param>
|
||||
/// <returns>A value indicating whether an Umbraco document was found and assigned.</returns>
|
||||
public override bool TryFindContent(PublishedContentRequest docRequest)
|
||||
{
|
||||
IPublishedContent node = null;
|
||||
var path = docRequest.Uri.GetAbsolutePathDecoded();
|
||||
var path = docRequest.Uri.GetAbsolutePathDecoded();
|
||||
|
||||
bool isProfile = false;
|
||||
var pos = path.LastIndexOf('/');
|
||||
var pos = path.LastIndexOf('/');
|
||||
if (pos > 0)
|
||||
{
|
||||
var memberLogin = path.Substring(pos + 1);
|
||||
path = path.Substring(0, pos);
|
||||
var memberLogin = path.Substring(pos + 1);
|
||||
path = path.Substring(0, pos);
|
||||
|
||||
if (path == GlobalSettings.ProfileUrl)
|
||||
{
|
||||
isProfile = true;
|
||||
LogHelper.Debug<ContentFinderByProfile>("Path \"{0}\" is the profile path", () => path);
|
||||
Logger.Debug<ContentFinderByProfile>("Path \"{0}\" is the profile path", () => path);
|
||||
|
||||
var route = docRequest.HasDomain ? (docRequest.Domain.RootNodeId.ToString() + path) : path;
|
||||
node = FindContent(docRequest, route);
|
||||
var route = docRequest.HasDomain ? (docRequest.Domain.RootNodeId.ToString() + path) : path;
|
||||
node = FindContent(docRequest, route);
|
||||
|
||||
if (node != null)
|
||||
{
|
||||
//TODO: Should be handled by Context Items class manager (http://issues.umbraco.org/issue/U4-61)
|
||||
docRequest.RoutingContext.UmbracoContext.HttpContext.Items["umbMemberLogin"] = memberLogin;
|
||||
}
|
||||
//TODO: Should be handled by Context Items class manager (http://issues.umbraco.org/issue/U4-61)
|
||||
docRequest.RoutingContext.UmbracoContext.HttpContext.Items["umbMemberLogin"] = memberLogin;
|
||||
}
|
||||
else
|
||||
{
|
||||
LogHelper.Debug<ContentFinderByProfile>("No document matching profile path?");
|
||||
Logger.Debug<ContentFinderByProfile>("No document matching profile path?");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isProfile)
|
||||
{
|
||||
LogHelper.Debug<ContentFinderByProfile>("Not the profile path");
|
||||
Logger.Debug<ContentFinderByProfile>("Not the profile path");
|
||||
}
|
||||
|
||||
return node != null;
|
||||
|
||||
@@ -19,6 +19,13 @@ namespace Umbraco.Web.Routing
|
||||
/// </remarks>
|
||||
public class ContentFinderByUrlAlias : IContentFinder
|
||||
{
|
||||
protected ILogger Logger { get; private set; }
|
||||
|
||||
public ContentFinderByUrlAlias(ILogger logger)
|
||||
{
|
||||
Logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to find and assign an Umbraco document to a <c>PublishedContentRequest</c>.
|
||||
/// </summary>
|
||||
@@ -37,7 +44,7 @@ namespace Umbraco.Web.Routing
|
||||
if (node != null)
|
||||
{
|
||||
docRequest.PublishedContent = node;
|
||||
LogHelper.Debug<ContentFinderByUrlAlias>("Path \"{0}\" is an alias for id={1}", () => docRequest.Uri.AbsolutePath, () => docRequest.PublishedContent.Id);
|
||||
Logger.Debug<ContentFinderByUrlAlias>("Path \"{0}\" is an alias for id={1}", () => docRequest.Uri.AbsolutePath, () => docRequest.PublishedContent.Id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core.LightInject;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.ObjectResolution;
|
||||
|
||||
@@ -8,17 +9,17 @@ namespace Umbraco.Web.Routing
|
||||
/// <summary>
|
||||
/// Resolves IPublishedContentFinder objects.
|
||||
/// </summary>
|
||||
public sealed class ContentFinderResolver : ManyObjectsResolverBase<ContentFinderResolver, IContentFinder>
|
||||
public sealed class ContentFinderResolver : ContainerManyObjectsResolver<ContentFinderResolver, IContentFinder>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ContentFinderResolver"/> class with an initial list of finder types.
|
||||
/// </summary>
|
||||
/// <param name="serviceProvider"></param>
|
||||
/// <param name="container"></param>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="finders">The list of finder types</param>
|
||||
/// <remarks>The resolver is created by the <c>WebBootManager</c> and thus the constructor remains internal.</remarks>
|
||||
internal ContentFinderResolver(IServiceProvider serviceProvider, ILogger logger, IEnumerable<Type> finders)
|
||||
: base(serviceProvider, logger, finders)
|
||||
internal ContentFinderResolver(IServiceContainer container, ILogger logger, IEnumerable<Type> finders)
|
||||
: base(container, logger, finders)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
@@ -26,10 +27,10 @@ namespace Umbraco.Web.Routing
|
||||
/// </summary>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="finders">The list of finder types</param>
|
||||
/// <param name="serviceProvider"></param>
|
||||
/// <param name="container"></param>
|
||||
/// <remarks>The resolver is created by the <c>WebBootManager</c> and thus the constructor remains internal.</remarks>
|
||||
internal ContentFinderResolver(IServiceProvider serviceProvider, ILogger logger, params Type[] finders)
|
||||
: base(serviceProvider, logger, finders)
|
||||
internal ContentFinderResolver(IServiceContainer container, ILogger logger, params Type[] finders)
|
||||
: base(container, logger, finders)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,20 +1,33 @@
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
using Umbraco.Core.LightInject;
|
||||
using Umbraco.Core.ObjectResolution;
|
||||
|
||||
namespace Umbraco.Web.Routing
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// Resolves the last chance IPublishedContentFinder object.
|
||||
/// </summary>
|
||||
public sealed class ContentLastChanceFinderResolver : SingleObjectResolverBase<ContentLastChanceFinderResolver, IContentFinder>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ContentLastChanceFinderResolver"/> class with no finder.
|
||||
/// </summary>
|
||||
/// <remarks>The resolver is created by the <c>WebBootManager</c> and thus the constructor remains internal.</remarks>
|
||||
internal ContentLastChanceFinderResolver()
|
||||
: base(true)
|
||||
{ }
|
||||
/// </summary>
|
||||
public sealed class ContentLastChanceFinderResolver : ContainerSingleObjectResolver<ContentLastChanceFinderResolver, IContentFinder>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes the resolver to use IoC
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
/// <param name="implementationType"></param>
|
||||
internal ContentLastChanceFinderResolver(IServiceContainer container, Type implementationType)
|
||||
: base(container, implementationType)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ContentLastChanceFinderResolver"/> class with no finder.
|
||||
/// </summary>
|
||||
/// <remarks>The resolver is created by the <c>WebBootManager</c> and thus the constructor remains internal.</remarks>
|
||||
internal ContentLastChanceFinderResolver()
|
||||
: base(true)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ContentLastChanceFinderResolver"/> class with an instance of a finder.
|
||||
@@ -24,24 +37,34 @@ namespace Umbraco.Web.Routing
|
||||
internal ContentLastChanceFinderResolver(IContentFinder finder)
|
||||
: base(finder, true)
|
||||
{ }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Sets the last chance finder.
|
||||
/// </summary>
|
||||
/// <param name="finder">The finder.</param>
|
||||
/// <remarks>For developers, at application startup.</remarks>
|
||||
public void SetFinder(IContentFinder finder)
|
||||
{
|
||||
Value = finder;
|
||||
}
|
||||
/// Initializes the resolver to use IoC
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
/// <param name="implementationType"></param>
|
||||
internal ContentLastChanceFinderResolver(IServiceContainer container, Expression<Func<IServiceFactory, IContentFinder>> implementationType)
|
||||
: base(container, implementationType)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the last chance finder.
|
||||
/// </summary>
|
||||
public IContentFinder Finder
|
||||
{
|
||||
get { return Value; }
|
||||
}
|
||||
/// <summary>
|
||||
/// Sets the last chance finder.
|
||||
/// </summary>
|
||||
/// <param name="finder">The finder.</param>
|
||||
/// <remarks>For developers, at application startup.</remarks>
|
||||
public void SetFinder(IContentFinder finder)
|
||||
{
|
||||
Value = finder;
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the last chance finder.
|
||||
/// </summary>
|
||||
public IContentFinder Finder
|
||||
{
|
||||
get { return Value; }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,38 +1,59 @@
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
using Umbraco.Core.LightInject;
|
||||
using Umbraco.Core.ObjectResolution;
|
||||
|
||||
namespace Umbraco.Web.Routing
|
||||
{
|
||||
/// <summary>
|
||||
/// Resolves the <see cref="ISiteDomainHelper"/> implementation.
|
||||
/// </summary>
|
||||
public sealed class SiteDomainHelperResolver : SingleObjectResolverBase<SiteDomainHelperResolver, ISiteDomainHelper>
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// Resolves the <see cref="ISiteDomainHelper"/> implementation.
|
||||
/// </summary>
|
||||
public sealed class SiteDomainHelperResolver : ContainerSingleObjectResolver<SiteDomainHelperResolver, ISiteDomainHelper>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes the resolver to use IoC
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
/// <param name="implementationType"></param>
|
||||
internal SiteDomainHelperResolver(IServiceContainer container, Type implementationType)
|
||||
: base(container, implementationType)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SiteDomainHelperResolver"/> class with an <see cref="ISiteDomainHelper"/> implementation.
|
||||
/// </summary>
|
||||
/// </summary>
|
||||
/// <param name="helper">The <see cref="ISiteDomainHelper"/> implementation.</param>
|
||||
internal SiteDomainHelperResolver(ISiteDomainHelper helper)
|
||||
: base(helper)
|
||||
{ }
|
||||
: base(helper)
|
||||
{ }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// Initializes the resolver to use IoC
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
/// <param name="implementationType"></param>
|
||||
internal SiteDomainHelperResolver(IServiceContainer container, Expression<Func<IServiceFactory, ISiteDomainHelper>> implementationType)
|
||||
: base(container, implementationType)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Can be used by developers at runtime to set their IDomainHelper at app startup
|
||||
/// </summary>
|
||||
/// </summary>
|
||||
/// <param name="helper"></param>
|
||||
public void SetHelper(ISiteDomainHelper helper)
|
||||
{
|
||||
Value = helper;
|
||||
}
|
||||
public void SetHelper(ISiteDomainHelper helper)
|
||||
{
|
||||
Value = helper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="ISiteDomainHelper"/> implementation.
|
||||
/// </summary>
|
||||
/// </summary>
|
||||
public ISiteDomainHelper Helper
|
||||
{
|
||||
get { return Value; }
|
||||
}
|
||||
}
|
||||
{
|
||||
get { return Value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,12 @@ namespace Umbraco.Web.Scheduling
|
||||
private static volatile bool _started = false;
|
||||
private static readonly object Locker = new object();
|
||||
|
||||
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
|
||||
/// <summary>
|
||||
/// Overridable method to execute when the ApplicationContext is created and other static objects that require initialization have been setup
|
||||
/// </summary>
|
||||
/// <param name="umbracoApplication"></param>
|
||||
/// <param name="applicationContext"></param>
|
||||
protected override void ApplicationInitialized(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
|
||||
{
|
||||
if (umbracoApplication.Context == null)
|
||||
return;
|
||||
|
||||
@@ -39,14 +39,14 @@ namespace Umbraco.Web.Standalone
|
||||
//var editorControlsAssemblyName = typeof(uploadField).Assembly.FullName;
|
||||
}
|
||||
|
||||
protected override void InitializeApplicationEventsResolver()
|
||||
{
|
||||
base.InitializeApplicationEventsResolver();
|
||||
foreach (var type in _handlersToAdd)
|
||||
ApplicationEventsResolver.Current.AddType(type);
|
||||
foreach (var type in _handlersToRemove)
|
||||
ApplicationEventsResolver.Current.RemoveType(type);
|
||||
}
|
||||
//protected override void InitializeApplicationEventsResolver()
|
||||
//{
|
||||
// base.InitializeApplicationEventsResolver();
|
||||
// foreach (var type in _handlersToAdd)
|
||||
// ApplicationEventsResolver.Current.AddType(type);
|
||||
// foreach (var type in _handlersToRemove)
|
||||
// ApplicationEventsResolver.Current.RemoveType(type);
|
||||
//}
|
||||
|
||||
protected override void InitializeResolvers()
|
||||
{
|
||||
@@ -63,7 +63,7 @@ namespace Umbraco.Web.Standalone
|
||||
|
||||
ContentLastChanceFinderResolver.Current = new ContentLastChanceFinderResolver();
|
||||
ContentFinderResolver.Current = new ContentFinderResolver(
|
||||
ServiceProvider, LoggerResolver.Current.Logger,
|
||||
Container, LoggerResolver.Current.Logger,
|
||||
typeof (ContentFinderByPageIdQuery),
|
||||
typeof (ContentFinderByNiceUrl),
|
||||
typeof (ContentFinderByIdPath)
|
||||
|
||||
@@ -264,6 +264,10 @@
|
||||
</Compile>
|
||||
<Compile Include="ApplicationContextExtensions.cs" />
|
||||
<Compile Include="AreaRegistrationContextExtensions.cs" />
|
||||
<Compile Include="LightInject\LightInjectExtensions.cs" />
|
||||
<Compile Include="LightInject\Mvc\LightInject.Mvc.cs" />
|
||||
<Compile Include="LightInject\WebApi\LightInject.WebApi.cs" />
|
||||
<Compile Include="LightInject\Web\LightInject.Web.cs" />
|
||||
<Compile Include="Models\ContentEditing\Relation.cs" />
|
||||
<Compile Include="Models\ContentEditing\RelationType.cs" />
|
||||
<Compile Include="Models\LegacyConvertedNode.cs" />
|
||||
|
||||
@@ -23,28 +23,6 @@ namespace Umbraco.Web
|
||||
/// </summary>
|
||||
public class UmbracoApplication : UmbracoApplicationBase
|
||||
{
|
||||
private ManifestWatcher _mw;
|
||||
|
||||
protected override void OnApplicationStarted(object sender, EventArgs e)
|
||||
{
|
||||
base.OnApplicationStarted(sender, e);
|
||||
|
||||
if (ApplicationContext.Current.IsConfigured && GlobalSettings.DebugMode)
|
||||
{
|
||||
_mw = new ManifestWatcher(LoggerResolver.Current.Logger);
|
||||
_mw.Start(Directory.GetDirectories(IOHelper.MapPath("~/App_Plugins/")));
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnApplicationEnd(object sender, EventArgs e)
|
||||
{
|
||||
base.OnApplicationEnd(sender, e);
|
||||
|
||||
if (_mw != null)
|
||||
{
|
||||
_mw.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
protected override IBootManager GetBootManager()
|
||||
{
|
||||
|
||||
@@ -14,6 +14,7 @@ using Examine;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Dictionary;
|
||||
using Umbraco.Core.LightInject;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Macros;
|
||||
using Umbraco.Core.ObjectResolution;
|
||||
@@ -23,6 +24,7 @@ using Umbraco.Core.PropertyEditors.ValueConverters;
|
||||
using Umbraco.Core.Sync;
|
||||
using Umbraco.Web.Dictionary;
|
||||
using Umbraco.Web.Install;
|
||||
using Umbraco.Web.LightInject;
|
||||
using Umbraco.Web.Macros;
|
||||
using Umbraco.Web.Media;
|
||||
using Umbraco.Web.Media.ThumbnailProviders;
|
||||
@@ -31,6 +33,7 @@ using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.PropertyEditors;
|
||||
using Umbraco.Web.PropertyEditors.ValueConverters;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.PublishedCache.XmlPublishedCache;
|
||||
using Umbraco.Web.Routing;
|
||||
using Umbraco.Web.Security;
|
||||
using Umbraco.Web.Scheduling;
|
||||
@@ -38,6 +41,8 @@ using Umbraco.Web.UI.JavaScript;
|
||||
using Umbraco.Web.WebApi;
|
||||
using umbraco.BusinessLogic;
|
||||
using ProfilingViewEngine = Umbraco.Core.Profiling.ProfilingViewEngine;
|
||||
using TypeHelper = Umbraco.Core.TypeHelper;
|
||||
using Umbraco.Core.LightInject;
|
||||
|
||||
|
||||
namespace Umbraco.Web
|
||||
@@ -49,7 +54,7 @@ namespace Umbraco.Web
|
||||
{
|
||||
private readonly bool _isForTesting;
|
||||
//NOTE: see the Initialize method for what this is used for
|
||||
private List<IIndexer> _indexesToRebuild = new List<IIndexer>();
|
||||
private readonly List<IIndexer> _indexesToRebuild = new List<IIndexer>();
|
||||
|
||||
public WebBootManager(UmbracoApplicationBase umbracoApplication)
|
||||
: this(umbracoApplication, false)
|
||||
@@ -74,7 +79,7 @@ namespace Umbraco.Web
|
||||
/// <returns></returns>
|
||||
public override IBootManager Initialize()
|
||||
{
|
||||
//This is basically a hack for this item: http://issues.umbraco.org/issue/U4-5976
|
||||
//This is basically a hack for this item: http://issues.umbraco.org/issue/U4-5976
|
||||
// when Examine initializes it will try to rebuild if the indexes are empty, however in many cases not all of Examine's
|
||||
// event handlers will be assigned during bootup when the rebuilding starts which is a problem. So with the examine 0.1.58.2941 build
|
||||
// it has an event we can subscribe to in order to cancel this rebuilding process, but what we'll do is cancel it and postpone the rebuilding until the
|
||||
@@ -83,6 +88,9 @@ namespace Umbraco.Web
|
||||
|
||||
base.Initialize();
|
||||
|
||||
//setup mvc and webapi services
|
||||
SetupMvcAndWebApi();
|
||||
|
||||
// Backwards compatibility - set the path and URL type for ClientDependency 1.5.1 [LK]
|
||||
ClientDependency.Core.CompositeFiles.Providers.XmlFileMapper.FileMapVirtualFolder = "~/App_Data/TEMP/ClientDependency";
|
||||
ClientDependency.Core.CompositeFiles.Providers.BaseCompositeFileProcessingProvider.UrlTypeDefault = ClientDependency.Core.CompositeFiles.Providers.CompositeUrlType.Base64QueryStrings;
|
||||
@@ -94,32 +102,17 @@ namespace Umbraco.Web
|
||||
ClientDependency.Core.CompositeFiles.CompositeDependencyHandler.MaxHandlerUrlLength = Math.Min(section.MaxQueryStringLength, section.MaxRequestLength);
|
||||
}
|
||||
|
||||
//set master controller factory
|
||||
ControllerBuilder.Current.SetControllerFactory(
|
||||
new MasterControllerFactory(FilteredControllerFactoriesResolver.Current));
|
||||
|
||||
//set the render view engine
|
||||
ViewEngines.Engines.Add(new RenderViewEngine());
|
||||
//set the plugin view engine
|
||||
ViewEngines.Engines.Add(new PluginViewEngine());
|
||||
|
||||
//set model binder
|
||||
ModelBinders.Binders.Add(new KeyValuePair<Type, IModelBinder>(typeof(RenderModel), new RenderModelBinder()));
|
||||
|
||||
////add the profiling action filter
|
||||
//GlobalFilters.Filters.Add(new ProfilingActionFilter());
|
||||
|
||||
//Register a custom renderer - used to process property editor dependencies
|
||||
var renderer = new DependencyPathRenderer();
|
||||
renderer.Initialize("Umbraco.DependencyPathRenderer", new NameValueCollection { { "compositeFileHandlerPath", "~/DependencyHandler.axd" } });
|
||||
ClientDependencySettings.Instance.MvcRendererCollection.Add(renderer);
|
||||
|
||||
InstallHelper insHelper = new InstallHelper(UmbracoContext.Current);
|
||||
var insHelper = new InstallHelper(UmbracoContext.Current);
|
||||
insHelper.DeleteLegacyInstaller();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Override this method in order to ensure that the UmbracoContext is also created, this can only be
|
||||
/// created after resolution is frozen!
|
||||
@@ -140,20 +133,9 @@ namespace Umbraco.Web
|
||||
/// <summary>
|
||||
/// Ensure the current profiler is the web profiler
|
||||
/// </summary>
|
||||
protected override void InitializeProfilerResolver()
|
||||
protected override IProfiler CreateProfiler()
|
||||
{
|
||||
base.InitializeProfilerResolver();
|
||||
|
||||
//Set the profiler to be the web profiler
|
||||
ProfilerResolver.Current.SetProfiler(new WebProfiler());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds custom types to the ApplicationEventsResolver
|
||||
/// </summary>
|
||||
protected override void InitializeApplicationEventsResolver()
|
||||
{
|
||||
base.InitializeApplicationEventsResolver();
|
||||
return new WebProfiler();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -171,9 +153,6 @@ namespace Umbraco.Web
|
||||
|
||||
base.Complete(afterComplete);
|
||||
|
||||
//Now, startup all of our legacy startup handler
|
||||
ApplicationEventsResolver.Current.InstantiateLegacyStartupHandlers();
|
||||
|
||||
//Ok, now that everything is complete we'll check if we've stored any references to index that need rebuilding and run them
|
||||
// (see the initialize method for notes) - we'll ensure we remove the event handler too in case examine manager doesn't actually
|
||||
// initialize during startup, in which case we want it to rebuild the indexes itself.
|
||||
@@ -205,10 +184,10 @@ namespace Umbraco.Web
|
||||
/// <summary>
|
||||
/// Creates the application cache based on the HttpRuntime cache
|
||||
/// </summary>
|
||||
protected override void CreateApplicationCache()
|
||||
protected override CacheHelper CreateApplicationCache()
|
||||
{
|
||||
//create a web-based cache helper
|
||||
ApplicationCache = new CacheHelper();
|
||||
return new CacheHelper();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -235,7 +214,7 @@ namespace Umbraco.Web
|
||||
//plugin controllers must come first because the next route will catch many things
|
||||
RoutePluginControllers();
|
||||
}
|
||||
|
||||
|
||||
private void RoutePluginControllers()
|
||||
{
|
||||
var umbracoPath = GlobalSettings.UmbracoMvcArea;
|
||||
@@ -308,6 +287,26 @@ namespace Umbraco.Web
|
||||
route.RouteHandler = new SurfaceRouteHandler();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called to customize the IoC container
|
||||
/// </summary>
|
||||
/// <param name="container"></param>
|
||||
internal override void ConfigureServices(ServiceContainer container)
|
||||
{
|
||||
base.ConfigureServices(container);
|
||||
|
||||
//IoC setup for LightInject for mvc/webapi
|
||||
Container.EnableMvc();
|
||||
Container.RegisterMvcControllers(PluginManager);
|
||||
container.EnablePerWebRequestScope();
|
||||
container.EnableWebApi(GlobalConfiguration.Configuration);
|
||||
container.RegisterApiControllers(PluginManager);
|
||||
|
||||
//register other services
|
||||
container.Register<IPublishedContentCache, PublishedContentCache>();
|
||||
container.Register<IPublishedMediaCache, PublishedMediaCache>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes all web based and core resolves
|
||||
/// </summary>
|
||||
@@ -315,7 +314,7 @@ namespace Umbraco.Web
|
||||
{
|
||||
base.InitializeResolvers();
|
||||
|
||||
XsltExtensionsResolver.Current = new XsltExtensionsResolver(ServiceProvider, LoggerResolver.Current.Logger, () => PluginManager.Current.ResolveXsltExtensions());
|
||||
XsltExtensionsResolver.Current = new XsltExtensionsResolver(ServiceProvider, ProfilingLogger.Logger, () => PluginManager.ResolveXsltExtensions());
|
||||
|
||||
//set the default RenderMvcController
|
||||
DefaultRenderMvcControllerResolver.Current = new DefaultRenderMvcControllerResolver(typeof(RenderMvcController));
|
||||
@@ -334,21 +333,21 @@ namespace Umbraco.Web
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LoggerResolver.Current.Logger.Error<WebBootManager>("An error occurred trying to set the IServerMessenger during application startup", e);
|
||||
ProfilingLogger.Logger.Error<WebBootManager>("An error occurred trying to set the IServerMessenger during application startup", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
LoggerResolver.Current.Logger.Warn<WebBootManager>("Could not initialize the DefaultServerMessenger, the application is not configured or the database is not configured");
|
||||
ProfilingLogger.Logger.Warn<WebBootManager>("Could not initialize the DefaultServerMessenger, the application is not configured or the database is not configured");
|
||||
return null;
|
||||
}));
|
||||
|
||||
SurfaceControllerResolver.Current = new SurfaceControllerResolver(
|
||||
ServiceProvider, LoggerResolver.Current.Logger,
|
||||
PluginManager.Current.ResolveSurfaceControllers());
|
||||
ServiceProvider, ProfilingLogger.Logger,
|
||||
PluginManager.ResolveSurfaceControllers());
|
||||
|
||||
UmbracoApiControllerResolver.Current = new UmbracoApiControllerResolver(
|
||||
ServiceProvider, LoggerResolver.Current.Logger,
|
||||
PluginManager.Current.ResolveUmbracoApiControllers());
|
||||
ServiceProvider, ProfilingLogger.Logger,
|
||||
PluginManager.ResolveUmbracoApiControllers());
|
||||
|
||||
// both TinyMceValueConverter (in Core) and RteMacroRenderingValueConverter (in Web) will be
|
||||
// discovered when CoreBootManager configures the converters. We HAVE to remove one of them
|
||||
@@ -360,15 +359,10 @@ namespace Umbraco.Web
|
||||
PropertyValueConvertersResolver.Current.RemoveType<Core.PropertyEditors.ValueConverters.TextStringValueConverter>();
|
||||
PropertyValueConvertersResolver.Current.RemoveType<Core.PropertyEditors.ValueConverters.MarkdownEditorValueConverter>();
|
||||
|
||||
PublishedCachesResolver.Current = new PublishedCachesResolver(new PublishedCaches(
|
||||
new PublishedCache.XmlPublishedCache.PublishedContentCache(),
|
||||
new PublishedCache.XmlPublishedCache.PublishedMediaCache(ApplicationContext)));
|
||||
|
||||
GlobalConfiguration.Configuration.Services.Replace(typeof(IHttpControllerSelector),
|
||||
new NamespaceHttpControllerSelector(GlobalConfiguration.Configuration));
|
||||
PublishedCachesResolver.Current = new PublishedCachesResolver(Container, typeof(PublishedCaches));
|
||||
|
||||
FilteredControllerFactoriesResolver.Current = new FilteredControllerFactoriesResolver(
|
||||
ServiceProvider, LoggerResolver.Current.Logger,
|
||||
ServiceProvider, ProfilingLogger.Logger,
|
||||
// add all known factories, devs can then modify this list on application
|
||||
// startup either by binding to events or in their own global.asax
|
||||
new[]
|
||||
@@ -377,44 +371,66 @@ namespace Umbraco.Web
|
||||
});
|
||||
|
||||
UrlProviderResolver.Current = new UrlProviderResolver(
|
||||
ServiceProvider, LoggerResolver.Current.Logger,
|
||||
//typeof(AliasUrlProvider), // not enabled by default
|
||||
ServiceProvider, ProfilingLogger.Logger,
|
||||
//typeof(AliasUrlProvider), // not enabled by default
|
||||
typeof(DefaultUrlProvider),
|
||||
typeof(CustomRouteUrlProvider)
|
||||
);
|
||||
|
||||
ContentLastChanceFinderResolver.Current = new ContentLastChanceFinderResolver(new ContentFinderByLegacy404());
|
||||
ContentLastChanceFinderResolver.Current = new ContentLastChanceFinderResolver(Container, typeof(ContentFinderByLegacy404));
|
||||
|
||||
ContentFinderResolver.Current = new ContentFinderResolver(
|
||||
ServiceProvider, LoggerResolver.Current.Logger,
|
||||
Container, ProfilingLogger.Logger,
|
||||
// all built-in finders in the correct order, devs can then modify this list
|
||||
// on application startup via an application event handler.
|
||||
typeof(ContentFinderByPageIdQuery),
|
||||
typeof(ContentFinderByNiceUrl),
|
||||
typeof(ContentFinderByIdPath),
|
||||
typeof (ContentFinderByNiceUrlAndTemplate),
|
||||
typeof (ContentFinderByProfile),
|
||||
typeof (ContentFinderByUrlAlias)
|
||||
typeof(ContentFinderByNiceUrlAndTemplate),
|
||||
typeof(ContentFinderByProfile),
|
||||
typeof(ContentFinderByUrlAlias)
|
||||
|
||||
);
|
||||
|
||||
SiteDomainHelperResolver.Current = new SiteDomainHelperResolver(new SiteDomainHelper());
|
||||
SiteDomainHelperResolver.Current = new SiteDomainHelperResolver(Container, typeof(SiteDomainHelper));
|
||||
|
||||
// ain't that a bit dirty?
|
||||
// ain't that a bit dirty? YES
|
||||
PublishedCache.XmlPublishedCache.PublishedContentCache.UnitTesting = _isForTesting;
|
||||
|
||||
ThumbnailProvidersResolver.Current = new ThumbnailProvidersResolver(
|
||||
ServiceProvider, LoggerResolver.Current.Logger,
|
||||
PluginManager.Current.ResolveThumbnailProviders());
|
||||
Container, ProfilingLogger.Logger,
|
||||
PluginManager.ResolveThumbnailProviders());
|
||||
|
||||
ImageUrlProviderResolver.Current = new ImageUrlProviderResolver(
|
||||
ServiceProvider, LoggerResolver.Current.Logger,
|
||||
PluginManager.Current.ResolveImageUrlProviders());
|
||||
ServiceProvider, ProfilingLogger.Logger,
|
||||
PluginManager.ResolveImageUrlProviders());
|
||||
|
||||
CultureDictionaryFactoryResolver.Current = new CultureDictionaryFactoryResolver(
|
||||
new DefaultCultureDictionaryFactory());
|
||||
CultureDictionaryFactoryResolver.Current = new CultureDictionaryFactoryResolver(Container, typeof(DefaultCultureDictionaryFactory));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets up MVC/WebApi services
|
||||
/// </summary>
|
||||
private void SetupMvcAndWebApi()
|
||||
{
|
||||
//set master controller factory
|
||||
ControllerBuilder.Current.SetControllerFactory(
|
||||
new MasterControllerFactory(FilteredControllerFactoriesResolver.Current));
|
||||
|
||||
//set the render view engine
|
||||
ViewEngines.Engines.Add(new RenderViewEngine());
|
||||
//set the plugin view engine
|
||||
ViewEngines.Engines.Add(new PluginViewEngine());
|
||||
|
||||
//set model binder
|
||||
ModelBinders.Binders.Add(new KeyValuePair<Type, IModelBinder>(typeof(RenderModel), new RenderModelBinder()));
|
||||
|
||||
////add the profiling action filter
|
||||
//GlobalFilters.Filters.Add(new ProfilingActionFilter());
|
||||
|
||||
GlobalConfiguration.Configuration.Services.Replace(typeof(IHttpControllerSelector),
|
||||
new NamespaceHttpControllerSelector(GlobalConfiguration.Configuration));
|
||||
}
|
||||
|
||||
private void OnInstanceOnBuildingEmptyIndexOnStartup(object sender, BuildingEmptyIndexOnStartupEventArgs args)
|
||||
{
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
<package id="dotless" version="1.4.1.0" targetFramework="net45" />
|
||||
<package id="Examine" version="0.1.59.2941" targetFramework="net45" />
|
||||
<package id="HtmlAgilityPack" version="1.4.6" targetFramework="net40" />
|
||||
<package id="LightInject.Mvc.Source" version="1.0.0.4" targetFramework="net45" />
|
||||
<package id="LightInject.Web.Source" version="1.0.0.7" targetFramework="net45" />
|
||||
<package id="LightInject.WebApi.Source" version="1.0.0.3" targetFramework="net45" />
|
||||
<package id="Lucene.Net" version="2.9.4.1" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.Mvc" version="4.0.30506.0" targetFramework="net40" />
|
||||
<package id="Microsoft.AspNet.Mvc.FixedDisplayModes" version="1.0.1" targetFramework="net40" />
|
||||
|
||||
Reference in New Issue
Block a user