Configure Asp.net WebForms 4 with Ninject and Log4net

Install the Nuget Package

Install-Package Ninject.Web

Modify NinjectWebCommon.cs

Put your registrations in:

private static void RegisterServices(IKernel kernel)

eg:

kernel.Bind<ISomeService>().To<SomeImplementation>().InSingletonScope();
kernel.Bind<ISomeOtherService>().To<SomeOtherImplementation>().InTransientScope();
kernel.Bind<ILog>().ToMethod(context => LogManager.GetLogger(context.Request.Target.Member.DeclaringType));

Add the XmlConfigurator.Configure(); code inside the NinjectWebCommon.cs

DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
bootstrapper.Initialize(CreateKernel);
XmlConfigurator.Configure();

All aspx.cs pages must inherit Ninject.Web.PageBase

Ninject.Web.PageBase

eg:

public partial class BasePage : Ninject.Web.PageBase
{
	protected void Page_Load(object sender, EventArgs e)
	{

	}
}

To use the IOC

public partial class somePath : BasePage
{
	[Inject]
	public ISomeService SomeService { get; set; }

	[Inject]
	public ILog Log { get; set; }
	...
}