Skip to content

Commit

Permalink
Merge pull request #10 from unic/feature/improve-servicesconfigurator
Browse files Browse the repository at this point in the history
Add flexibility to change the base path and add extension points
  • Loading branch information
hombreDelPez authored Aug 24, 2017
2 parents 7045641 + b710cf3 commit bc0505f
Showing 1 changed file with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Web;
using System.Web.Hosting;
using System.Web.Hosting;
using Microsoft.Extensions.DependencyInjection;
using NitroNet.Mvc;
using NitroNet.Sitecore.Caching;
Expand All @@ -11,6 +10,8 @@
using NitroNet.ViewEngine.TemplateHandler;
using NitroNet.ViewEngine.TemplateHandler.Grid;
using NitroNet.ViewEngine.ViewEngines;
using Sitecore;
using Sitecore.Configuration;
using Sitecore.DependencyInjection;
using Sitecore.Mvc.Common;
using Veil;
Expand All @@ -19,6 +20,7 @@

namespace NitroNet.Sitecore.Microsoft.DependencyInjection
{
[UsedImplicitly]
public class NitroNetServicesConfigurator : IServicesConfigurator
{
public void Configure(IServiceCollection serviceCollection)
Expand All @@ -27,7 +29,7 @@ public void Configure(IServiceCollection serviceCollection)
RegisterNitroNetSitecore(serviceCollection);
}

private static void RegisterNitroNetSitecore(IServiceCollection serviceCollection)
protected virtual void RegisterNitroNetSitecore(IServiceCollection serviceCollection)
{
serviceCollection.AddTransient<SitecoreNitroNetViewEngine>();
serviceCollection.AddTransient<ISitecoreRenderingRepository, SitecoreRenderingRepository>();
Expand All @@ -36,13 +38,13 @@ private static void RegisterNitroNetSitecore(IServiceCollection serviceCollectio
serviceCollection.AddSingleton<INitroTemplateHandlerFactory, SitecoreMvcNitroTemplateHandlerFactory>();
}

private static void RegisterNitroNet(IServiceCollection serviceCollection)
protected virtual void RegisterNitroNet(IServiceCollection serviceCollection)
{
var rootPath = HostingEnvironment.MapPath("~/");
var basePath = this.GetNitroNetBasePath();

var config = ConfigurationLoader.LoadNitroConfiguration(rootPath);
var config = ConfigurationLoader.LoadNitroConfiguration(basePath);
serviceCollection.AddSingleton(config);
serviceCollection.AddSingleton<IFileSystem>(new FileSystem(rootPath, config));
serviceCollection.AddSingleton<IFileSystem>(new FileSystem(basePath, config));

serviceCollection.AddSingleton<IHelperHandlerFactory, DefaultRenderingHelperHandlerFactory>();
serviceCollection.AddTransient<IMemberLocator, MemberLocatorFromNamingRule>();
Expand All @@ -54,5 +56,13 @@ private static void RegisterNitroNet(IServiceCollection serviceCollection)
serviceCollection.AddSingleton<ITemplateRepository, NitroTemplateRepository>();
serviceCollection.AddSingleton<INitroTemplateHandlerFactory, MvcNitroTemplateHandlerFactory>();
}

protected virtual string GetNitroNetBasePath()
{
var rootPath = HostingEnvironment.MapPath("~/");
var basePath = PathInfo.Combine(PathInfo.Create(rootPath), PathInfo.Create(Settings.GetAppSetting("NitroNet.BasePath")));

return basePath.ToString();
}
}
}

0 comments on commit bc0505f

Please sign in to comment.