Removed some of the old legacy configs
Signed-off-by: Bjarke Berg <mail@bergmania.dk>
This commit is contained in:
@@ -15,13 +15,6 @@ namespace Umbraco.ModelsBuilder.Embedded.Compose
|
||||
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
|
||||
public sealed class ModelsBuilderComposer : ICoreComposer
|
||||
{
|
||||
private readonly ModelsBuilderConfig _config;
|
||||
|
||||
public ModelsBuilderComposer(IOptions<ModelsBuilderConfig> config)
|
||||
{
|
||||
_config = config.Value;
|
||||
}
|
||||
|
||||
public void Compose(Composition composition)
|
||||
{
|
||||
composition.Components().Append<ModelsBuilderComponent>();
|
||||
@@ -31,44 +24,43 @@ namespace Umbraco.ModelsBuilder.Embedded.Compose
|
||||
composition.RegisterUnique<OutOfDateModelsStatus>();
|
||||
composition.RegisterUnique<ModelsGenerationError>();
|
||||
|
||||
if (_config.ModelsMode == ModelsMode.PureLive)
|
||||
ComposeForLiveModels(composition);
|
||||
else if (_config.EnableFactory)
|
||||
ComposeForDefaultModelsFactory(composition);
|
||||
}
|
||||
|
||||
private void ComposeForDefaultModelsFactory(Composition composition)
|
||||
{
|
||||
composition.RegisterUnique<IPublishedModelFactory>(factory =>
|
||||
{
|
||||
var typeLoader = factory.GetInstance<TypeLoader>();
|
||||
var publishedValueFallback = factory.GetInstance<IPublishedValueFallback>();
|
||||
var types = typeLoader
|
||||
.GetTypes<PublishedElementModel>() // element models
|
||||
.Concat(typeLoader.GetTypes<PublishedContentModel>()); // content models
|
||||
return new PublishedModelFactory(types, publishedValueFallback);
|
||||
var config = factory.GetInstance<IOptions<ModelsBuilderConfig>>().Value;
|
||||
if (config.ModelsMode == ModelsMode.PureLive)
|
||||
{
|
||||
composition.RegisterUnique<IPublishedModelFactory, PureLiveModelFactory>();
|
||||
|
||||
// the following would add @using statement in every view so user's don't
|
||||
// have to do it - however, then noone understands where the @using statement
|
||||
// comes from, and it cannot be avoided / removed --- DISABLED
|
||||
//
|
||||
/*
|
||||
// no need for @using in views
|
||||
// note:
|
||||
// we are NOT using the in-code attribute here, config is required
|
||||
// because that would require parsing the code... and what if it changes?
|
||||
// we can AddGlobalImport not sure we can remove one anyways
|
||||
var modelsNamespace = Configuration.Config.ModelsNamespace;
|
||||
if (string.IsNullOrWhiteSpace(modelsNamespace))
|
||||
modelsNamespace = Configuration.Config.DefaultModelsNamespace;
|
||||
System.Web.WebPages.Razor.WebPageRazorHost.AddGlobalImport(modelsNamespace);
|
||||
*/
|
||||
}
|
||||
else if (config.EnableFactory)
|
||||
{
|
||||
var typeLoader = factory.GetInstance<TypeLoader>();
|
||||
var publishedValueFallback = factory.GetInstance<IPublishedValueFallback>();
|
||||
var types = typeLoader
|
||||
.GetTypes<PublishedElementModel>() // element models
|
||||
.Concat(typeLoader.GetTypes<PublishedContentModel>()); // content models
|
||||
return new PublishedModelFactory(types, publishedValueFallback);
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
private void ComposeForLiveModels(Composition composition)
|
||||
{
|
||||
composition.RegisterUnique<IPublishedModelFactory, PureLiveModelFactory>();
|
||||
|
||||
// the following would add @using statement in every view so user's don't
|
||||
// have to do it - however, then noone understands where the @using statement
|
||||
// comes from, and it cannot be avoided / removed --- DISABLED
|
||||
//
|
||||
/*
|
||||
// no need for @using in views
|
||||
// note:
|
||||
// we are NOT using the in-code attribute here, config is required
|
||||
// because that would require parsing the code... and what if it changes?
|
||||
// we can AddGlobalImport not sure we can remove one anyways
|
||||
var modelsNamespace = Configuration.Config.ModelsNamespace;
|
||||
if (string.IsNullOrWhiteSpace(modelsNamespace))
|
||||
modelsNamespace = Configuration.Config.DefaultModelsNamespace;
|
||||
System.Web.WebPages.Razor.WebPageRazorHost.AddGlobalImport(modelsNamespace);
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user