I am using Asp.Net webform.In my web projects I can use property injection but in my class library how I can resolve my class from NinjectWebCommon ? I dont want create a new instance if it is alive.
In my web project I am using Ninject.Web.PageBase,Ninject.Web.MasterPageBase but in my class library ?
Web Project packages : Ninject 3.2.0 , Ninject.Web 3.2.1 , Ninject.Web.Common 3.2.0 and Ninject.Web.Common.WebHost.
public static class NinjectWeb
{
/// <summary>
/// Starts the application
/// </summary>
public static void Start()
{
DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
}
}
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();
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)
{
kernel.Bind<IUserService>().To<UserService>();
kernel.Bind<IUserRepo>().To<UserRepo>();
kernel.Bind<IRoleService>().To<RoleService>();
kernel.Bind<IRoleRepo>().To<RoleRepo>();
}
}
Comments
Post a Comment