DotVvmServiceCollectionExtensions.cs
Home
/
src /
Web /
Helpers /
DotVvmServiceCollectionExtensions.cs
namespace Web.Helpers
{
using Castle.MicroKernel.Registration;
using Castle.Windsor;
using DotVVM.Framework.ViewModel.Serialization;
using Infrastructure;
using Microsoft.Extensions.DependencyInjection;
using System.IO;
using System.Web.Hosting;
public static class DotVvmServiceCollectionExtensions
{
private static WindsorContainer _windsorContainer;
// https://www.dotvvm.com/docs/2.0/pages/advanced-ioc-di-container-owin
public static IDotvvmServiceCollection ConfigureCastleWindsor(this IDotvvmServiceCollection svc)
{
_windsorContainer = new WindsorContainer();
// ReSharper disable once PossibleNullReferenceException
_windsorContainer.Register(Classes.FromThisAssembly()
.InNamespace(Constants.ViewModelsNamespace)
.LifestyleTransient()
.WithServiceDefaultInterfaces());
_windsorContainer.Kernel.Resolver.AddSubResolver(new ServiceCollectionResolver(svc.Services));
svc.Services.AddSingleton<IViewModelLoader>(_ => new WindsorViewModelLoader(_windsorContainer));
//svc.Services.AddSingleton<IStaticCommandServiceLoader>(_ => new WindsorStaticCommandServiceLoader(_windsorContainer));
svc.RegisterDependencies();
return svc;
}
public static IDotvvmServiceCollection ConfigureDefaultTemporaryStorage(this IDotvvmServiceCollection svc)
{
var path = Path.Combine(HostingEnvironment.ApplicationPhysicalPath, Constants.DefaultTemporaryStoragePath);
svc.AddDefaultTempStorages(path);
return svc;
}
#region Private Methods
private static IDotvvmServiceCollection RegisterDependencies(this IDotvvmServiceCollection svc)
{
return svc;
}
#endregion
}
}