using System;
using System.Web;
using Glass.Mapper.Sc;
using Glass.Mapper.Sc.CastleWindsor;
using Microsoft.Web.Infrastructure.DynamicModuleHelper;
using Ninject;
using Ninject.Syntax;
using Ninject.Web.Common;
using SeitenKern;
using SeitenKern.Infrastructure.DependencyInjection.Modules;
using Config = Glass.Mapper.Sc.CastleWindsor.Config;
[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(NinjectWebCommon), "Start")]
[assembly: WebActivatorEx.ApplicationShutdownMethodAttribute(typeof(NinjectWebCommon), "Stop")]
namespace SeitenKern
{
public static class NinjectWebCommon
{
private static readonly Bootstrapper Bootstrapper = new Bootstrapper();
/// <summary>
/// Starts the application
/// </summary>
public static void Start()
{
DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
Bootstrapper.Initialize(CreateKernel);
}
/// <summary>
/// Stops the application.
/// </summary>
public static void Stop()
{
Bootstrapper.ShutDown();
}
/// <summary>
/// Creates the kernel that will manage your application.
/// </summary>
/// <returns>The created kernel.</returns>
private static IKernel CreateKernel()
{
var kernel = new StandardKernel(new SeitenKernModule());
try
{
kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
RegisterServices(kernel);
return kernel;
}
catch
{
kernel.Dispose();
throw;
}
}
/// <summary>
/// Load your modules or register your services here!
/// </summary>
/// <param name="kernel">The kernel.</param>
private static void RegisterServices(IKernel kernel)
{
}
}
}using Glass.Mapper.Sc;
using Ninject.Modules;
namespace SeitenKern.Infrastructure.DependencyInjection.Modules
{
public class SeitenKernModule : NinjectModule
{
public override void Load()
{
Bind<ISitecoreContext>().To<SitecoreContext>();
}
}
}using System;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using Glass.Mapper.Sc;
using Ninject;
using Ninject.Web.Common;
using SeitenKern.Infrastructure.Controls;
using SeitenKern.Models;
using SeitenKern.SitecoreContrib;
using Sitecore.Data;
using Sitecore.Links;
using Sitecore.Platform;
using Sitecore.Web.UI.WebControls;
namespace SeitenKern.layouts.SeitenKern
{
public partial class SeitenKernBase : BasePage
{
[Inject]
public ISitecoreContext SitecoreContext { get; set; }
public HomePage HomePageModel { get; set; }
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
var kernel = new Bootstrapper().Kernel;
kernel.Inject(this);
HomePageModel = SitecoreContext.GetCurrentItem<HomePage>();
}
}
}