Coder Social home page Coder Social logo

ninject.web's Introduction

Ninject

Build status codecov NuGet Version NuGet Downloads

Ninject is a lightning-fast, ultra-lightweight dependency injector for .NET applications. It helps you split your application into a collection of loosely-coupled, highly-cohesive pieces, and then glue them back together in a flexible manner. By using Ninject to support your software's architecture, your code will become easier to write, reuse, test, and modify.

Write your code so it's flexible...

public class Samurai {
    public IWeapon Weapon { get; private set; }
    public Samurai(IWeapon weapon) 
    {
        this.Weapon = weapon;
    }
}

...and let Ninject glue it together for you.

public class WarriorModule : NinjectModule
{
    public override void Load() 
    {
        this.Bind<IWeapon>().To<Sword>();
    }
}

Features:

  1. Focused. Too many existing dependency injection projects sacrifice usability for features that aren't often necessary. Each time a feature is added to Ninject, its benefit is weighed against the complexity it adds to everyday use. Our goal is to keep the barrier to entry - the baseline level of knowledge required to use Ninject - as low as possible. Ninject has many advanced features, but understanding them is not required to use the basic features.

  2. Sleek. Framework bloat is a major concern for some projects, and as such, all of Ninject's core functionality is in a single assembly with no dependencies outside the .NET base class library. This single assembly's footprint is approximately 85KB when compiled for release.

  3. Fast. Instead of relying on reflection for invocation, Ninject takes advantage of lightweight code generation in the CLR. This can result in a dramatic (8-50x) improvement in performance in many situations.

  4. Precise. Ninject helps developers get things right the first time around. Rather than relying on XML mapping files and string identifiers to wire up components, Ninject provides a robust domain-specific language. This means that Ninject takes advantage of the capabilities of the language (like type-safety) and the IDE (like IntelliSense and code completion).

  5. Agile. Ninject is designed around a component-based architecture, with customization and evolution in mind. Many facets of the system can be augmented or modified to fit the requirements of each project.

  6. Stealthy. Ninject will not invade your code. You can easily isolate the dependency on Ninject to a single assembly in your project.

  7. Powerful. Ninject includes many advanced features. For example, Ninject is the first dependency injector to support contextual binding, in which a different concrete implementation of a service may be injected depending on the context in which it is requested.

Everything else is in Extensions

Yes, sounds slim and focused, but where is the support for all the features that the competitors have?

Generally, they are maintained as specific focused extensions with owners who keep them in sync and pull in new ideas and fixes fast. These are summarized on the extensions section of the project website. Most are hosted alongside the core project right here.

License

Ninject is intended to be used in both open-source and commercial environments. To allow its use in as many situations as possible, Ninject is dual-licensed. You may choose to use Ninject under either the Apache License, Version 2.0, or the Microsoft Public License (Ms-PL). These licenses are essentially identical, but you are encouraged to evaluate both to determine which best fits your intended use.

Refer to LICENSE.txt for detailed information.

Changes history

Resources

ninject.web's People

Contributors

iappert avatar idavis avatar remogloor avatar scott-xu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ninject.web's Issues

Conflicting with ASP.NET DynamicData

Hi, Ive been using your extension for few months now, it's really good thank for all your hard work.

In a bid to make things easier for myself to maintain a clients database without having to go through tech support everytime I decided to give ASP.NET DynamicData a go.

Having cofigure it using the following instructions
http://msdn.microsoft.com/en-us/library/ee923692.aspx

It works, kind-of.. but when you hit postback on a DynamicData form the form disapear and nothing happens. I thought perhaps it could of been an issue with ninject.web and ajax, I tested a basic update panel and that works fine so it appears it to do souly with DynamicData.

The pages for DynamicData are completly generated so it would seem that on postback the form controls arent generated therefore the events dont get mapped back to the controls on post back so no events fire to update the data.

I dont suppose you could of offer any suggestions as I want to keep using ninject.web

Thanks

Mantisimo

Installing Ninject.Web affects existing FindControl calls

I installed Ninject.Web recently so that I could begin injecting dependencies into my VB.NET Web Forms pages. This works without any problems, but I noticed that other pages (whose own code has not been changed in any way) break after the NuGet package is installed. Uninstall it and the errors go away.

Specifically, a lot of the code uses FindControl in or near Page_Load and returns null once Ninject.Web has been installed, causing null reference exceptions (I don't know if this is bad practice to use FindControl in Page_Load but the application is large and inherited and I'd rather keep it stable than introduce a bunch of unknowns at this time).

I used Debug.WriteLine with and without Ninject.Web on some of my code. In it, I use a method that recursively prints all of the child controls of a parent control. [I should mention that the parent control in this particular case is a FormView.]

Without Ninject.Web:

Page_Load Begins
Name of Parent Control
Parent Control Data Binding Begins and Ends
Names of Child Controls
Page_Load

With Ninject.Web:

Page_Load Begins
Name of Parent Control
[No child controls printed; this is where null reference would occur if using FindControl]
Page_Load Ends
Parent Control Data Binding Begins and Ends

As you can see, once Ninject.Web as been installed, the databinding occurs after Page_Load, so the method that prints all of the control names stops at the parent control.

I am not familiar enough with Web Forms to know why this might occur, and I don't see anything in the Ninject.Web source that would cause this. Any insight would be greatly appreciated.

Ninject.Web.UserControlBase - not available with Ninject.Web.dll

Hi,

I Google this a lot, then I came to know that there is a new UserControlBase for asp.net (pure and not MVC) .

Today, I extracted the latest Ninject.Web from GitHub. I added these Ninject.dll and Ninject.Web.dll to my project and while I tried to create basecontrol page similar to :

public class BasePage : Ninject.Web.PageBase
{
}

Its not working. I extracted the Source code from GitHub and noticed that UserControlBase.cs is available under /ninject-ninject.web-ade0ef6\src\Ninject.Web.

If this is available why I can't access it.

Please ignore if this is not an issue, but reply to this issue .

Thanks & regards,
Gaurav Arora

Ninject 3.3.4 compatibility

I was trying to update all nInject packages in my solution and I realized I cannot update to latest nInject 3.3.4 because nInject.Web has dependency Ninject (>= 3.2.0 && < 3.3.0).

Can this package be updated for compatibility with nInject 3.3.4.

I would do the change even myself and issues a pull request but I don't know how this package has been built so how would I test it.

NinjectWebCommon bootstrapping appears broken.

I've tested the bootstrapping in NinjectWebCommon by creating a new ASP.NET Web Forms Site using VS2012 and adding a Services project with a DummyService. I can get my example to work with an override of CreateKernel in Global.asax but not if I use the Bootstrapper. Also, my WebForm pages must inherit from Ninject.Web.PageBase to work.

I've pushed my DemoNinject web site up to github to illustrate what works and what doesn't: https://github.com/Boggin/DemoNinject

system.notsupportedexception the static container already has a kernel associated with it

ASP.NET MVC5 NINJECT
system.notsupportedexception the static container already has a kernel associated with it

The static container already has a kernel associated with it!

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NotSupportedException: The static container already has a kernel associated with it!

Source Error:

Line 25: DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
Line 26: DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
Line 27: bootstrapper.Initialize(CreateKernel);
Line 28: }
Line 29:

Source File: d:\Projects\Astech\Systems\SportBettingSystem\Workspace\0.0.1\SportBettingSystem\SportBettingSysem.WebClient\App_Start\NinjectWebCommon.cs Line: 27

Stack Trace:

[NotSupportedException: The static container already has a kernel associated with it!]
Ninject.Web.KernelContainer.set_Kernel(IKernel value) +89
Ninject.Web.NinjectWebHttpApplicationPlugin.Start() +32
Ninject.Web.Common.Bootstrapper.b__0(INinjectHttpApplicationPlugin c) +29
Ninject.Infrastructure.Language.ExtensionsForIEnumerableOfT.Map(IEnumerable1 series, Action1 action) +194
Ninject.Web.Common.Bootstrapper.Initialize(Func`1 createKernelCallback) +205
SportBettingSystem.WebClient.NinjectWebCommon.Start() in d:\Projects\Astech\Systems\SportBettingSystem\Workspace\0.0.1\SportBettingSystem\SportBettingSysem.WebClient\App_Start\NinjectWebCommon.cs:27

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +192
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +155
System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +19
WebActivatorEx.BaseActivationMethodAttribute.InvokeMethod() +236
WebActivatorEx.ActivationManager.RunActivationMethods(Boolean designerMode) +619
WebActivatorEx.ActivationManager.RunPreStartMethods(Boolean designerMode) +48
WebActivatorEx.ActivationManager.Run() +75

[InvalidOperationException: The pre-application start initialization method Run on type WebActivatorEx.ActivationManager threw an exception with the following error message: Exception has been thrown by the target of an invocation..]
System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection1 methods, Func1 setHostingEnvironmentCultures) +547
System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +132
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +102
System.Web.Compilation.BuildManager.ExecutePreAppStart() +153
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +521

[HttpException (0x80004005): The pre-application start initialization method Run on type WebActivatorEx.ActivationManager threw an exception with the following error message: Exception has been thrown by the target of an invocation..]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9930508
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34212

Nuget Package with support for VB.net

I have to use VB.net in some projects. Adding Ninject.Web to my solution via Nuget adds the NinjectWeb.cs and NinjectWebCommon.cs files. But this is a VB.net project...

So we need a VB template in Nuget.

Ninject.web is not working with pages that contain ObjectDataSource

I have a webforms applications and I am trying to use ninject in as I used Ninject in mvc before I followed some posts and worked for me in most pages except pages that contains ObjectDataSource, these pages throws NullReferenceException - I think it means no dependancy injection happened - my code is as follows :

Web.Admin.Grades.aspx:

     <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"  EnablePaging="true" TypeName="Web.Admin.Grades"  SelectMethod="GetData" SelectCountMethod="GetDataCount"
                StartRowIndexParameterName="StartRowIndex" MaximumRowsParameterName="MaximumRows">
                <SelectParameters>
                    <asp:ControlParameter ControlID="SearchTxtBox" Type="String" Name="SearchKeyWord"                      PropertyName="Text" />
                </SelectParameters>
            </asp:ObjectDataSource>

Web.Admin.Grades.cs:

[Inject]
public IGradesRepository _Grades { get; set; }

public IList GetData(string SearchKeyWord, int StartRowIndex, int MaximumRows)
{
return _Grades.GetGrades(SearchKeyWord, StartRowIndex, MaximumRows);
}

public int GetDataCount(string SearchKeyWord)
{
return _Grades.GetGradesCount(SearchKeyWord);
}

How do you access IKernel?

I'm attempting to wire up Ninject to a webforms app that utilizes a custom MVP framework. Where Presenters are instantiated is currently done with reflection I'd like to leverage Ninject instead to instantiate and inject constructor arguments. I see bootstrapper stores the IKernel, but how do I access IKernel elsewhere (where my presenters are instantiated).

It's hard to inject components into UserControls

Hello.
It seems that the current implementation already has code that is responsible for the component injection into the UserControl.
I'm talking about the private void Ninject.Web.NinjectHttpModule.InjectUserControls(Control parent)
Unfortunately it doesn't work.
As a workaround I've created the following class:

public class NinjectUserControlBase : UserControl
{
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
RequestActivation();
}

///

/// Asks the kernel to inject this instance.
///

protected virtual void RequestActivation()
{
KernelContainer.Inject(this);
}
}

So, If you think that NinjectUserControlBase is useful just let me know to create a pull request.
Thanks.

AutoEventWireup and Injection

I have a question and maybe a potential bug to report, in case developer turns on the AutoEventWireup on System.Web.UI.Page or System.Web.UI.UserControl and uses let's say Init event e.g. "protected void Page_Init(object sender, EventArgs e)" at this point nothing is injected into properties etc.

The root of this problem is the call to RequestActivation(); in PageBase and UserControlBase which is called after base.OnInit(e); and all events are raised inside the base.OnInit.

Thoughts ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.