Created
September 6, 2012 17:44
-
-
Save ungood/3658896 to your computer and use it in GitHub Desktop.
Example Ninject Binding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Web; | |
using BBCom.Gotham.Domain; | |
using BBCom.Gotham.Service; | |
using GothamMVC3.Helpers; | |
using GothamMVC3.Navigation; | |
using Ninject; | |
using Ninject.Modules; | |
using Ninject.Web.Common; | |
using Ninject.Extensions.Conventions; | |
using Telerik.Web.Mvc; | |
using Telerik.Web.Mvc.Infrastructure; | |
using ICacheProvider = BBCom.Gotham.Service.ICacheProvider; | |
namespace GothamMVC3 | |
{ | |
public class GothamMvcModule : NinjectModule | |
{ | |
public override void Load() | |
{ | |
Bind<Application>() | |
.ToConstant(Application.GothamMVC3); | |
Bind<HttpContextBase>() | |
.ToMethod(ctx => new HttpContextWrapper(HttpContext.Current)) | |
.InRequestScope(); | |
Bind<HttpSessionStateBase>() | |
.ToMethod(ctx => new HttpSessionStateWrapper(HttpContext.Current.Session)) | |
.InRequestScope(); | |
Rebind<ICacheProvider>().To<SessionCacheProvider>() | |
.InRequestScope(); | |
Kernel.Bind(scanner => scanner | |
.FromThisAssembly() | |
.Select(type => type.Name.EndsWith("Service")) | |
.BindAllInterfaces() | |
.Configure(cfg => cfg.InRequestScope())); | |
Kernel.Bind<INavigationItemAuthorization>() | |
.To<GothamNavigationItemAuthorization>() | |
.InRequestScope(); | |
Kernel.Rebind<IMenuItemService>() | |
.To<MenuItemService>() | |
.InRequestScope(); | |
Kernel.Rebind<ISecurityService>() | |
.To<GothamSecurityService>() | |
.InRequestScope(); | |
// Setting up some static classes (TODO: is there a better way to do this?) | |
Security.GetSecurityService = () => Kernel.Get<ISecurityService>(); | |
GothamSiteMap.GetService = () => Kernel.Get<IMenuItemService>(); | |
// Redirect Telerik DI to Ninject | |
DI.Current.Register(() => Kernel.Get<INavigationItemAuthorization>()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment