1
0
mirror of https://github.com/rudollee/LearningMVC.git synced 2026-08-11 08:22:53 +00:00
EssentialTools
Ninject
This commit is contained in:
wook
2017-04-04 23:28:37 +09:00
parent 7c004e28e1
commit 0eaa6708fe
21 changed files with 696 additions and 1 deletions
@@ -0,0 +1,58 @@
[assembly: WebActivator.PreApplicationStartMethod(typeof(LanguageFeatures.App_Start.NinjectWebCommon), "Start")]
[assembly: WebActivator.ApplicationShutdownMethodAttribute(typeof(LanguageFeatures.App_Start.NinjectWebCommon), "Stop")]
namespace LanguageFeatures.App_Start
{
using System;
using System.Web;
using Microsoft.Web.Infrastructure.DynamicModuleHelper;
using Ninject;
using Ninject.Web.Common;
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();
kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
RegisterServices(kernel);
return kernel;
}
/// <summary>
/// Load your modules or register your services here!
/// </summary>
/// <param name="kernel">The kernel.</param>
private static void RegisterServices(IKernel kernel)
{
}
}
}
+3 -1
View File
@@ -106,7 +106,9 @@
</ItemGroup>
<ItemGroup>
<Content Include="Views\web.config" />
<Content Include="packages.config" />
<Content Include="packages.config">
<SubType>Designer</SubType>
</Content>
<Content Include="Views\Home\Result.cshtml" />
<None Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>