ninject

Specific down-sides to many-'small'-assemblies?

谁说我不能喝 提交于 2019-11-27 19:26:22
I am planning out some work to introduce Dependency Injection into what is currently a large monolithic library in an attempt to make the library easier to unit-test, easier to understand, and possibly more flexible as a bonus. I have decided to use NInject , and I really like Nate's motto of 'do one thing, do it well' (paraphrased), and it seems to go particularly well within the context of DI. What I have been wondering now, is whether I should split what is currently a single large assembly into multiple smaller assemblies with disjoint feature sets. Some of these smaller assemblies will

Options for wiring dependencies with NInject

最后都变了- 提交于 2019-11-27 19:25:10
问题 With NInject (preferably 2.0), what options do we have wrt wiring up our object dependencies in a web application? Can they be defined in an XML configuration file? Or does it have to be done via code? 回答1: Ninject doesn't have XML configuration, sorry but I can't provide a direct link (cos their site has flash elements), but here is a quotation from ninject.org: Free yourself from XML Most other .NET dependency injection frameworks are designed around the use of XML to declare type bindings.

Ninject InSingletonScope with Web Api RC

情到浓时终转凉″ 提交于 2019-11-27 19:08:07
I'm having some difficulty using Ninject's InSingletonScope binding with Web Api RC. No matter how I create my binding, it looks like perhaps Web Api is handling scope/lifetime instead of Ninject. I've tried a few variations on wiring up Ninject. The most common is identical to the answer here: ASP.NET Web API binding with ninject I've also tried this version: http://www.peterprovost.org/blog/2012/06/19/adding-ninject-to-web-api/ In both, I'm literally creating an out of the box Web Api project, then adding the Ninject packages as described in either post. Finally, I'm adding the Resolver and

What is the intention of Ninject modules?

与世无争的帅哥 提交于 2019-11-27 18:40:28
I'm a complete newbie to ninject I've been pulling apart someone else's code and found several instances of nInject modules - classes that derive from Ninject.Modules.Module, and have a load method that contains most of their code. These classes are called by invoking the LoadModule method of an instance of StandardKernel and passing it an instance of the module class. Maybe I'm missing something obvious here, but what is the benefit of this over just creating a plain old class and calling its method, or perhaps a static class with a static method? Jarrett Meyer The Ninject modules are the

Ninject + MVC3 = InvalidOperationException: Sequence contains no elements

拜拜、爱过 提交于 2019-11-27 18:14:13
I created a new MVC3 project, hit F5, saw the sample page. Then I used NuGet to get the Ninject.MVC extension . I modified my global.asax according to the Ninject documentation, How To Setup an MVC3 Application : public class MvcApplication : NinjectHttpApplication { public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErrorAttribute()); } public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new {

Inject Array of Interfaces in Ninject

痴心易碎 提交于 2019-11-27 16:01:49
问题 Consider the following code. public interface IFoo { } public class Bar { public Bar(IFoo[] foos) { } } public class MyModule : NinjectModule { public override void Load() { Bind<IFoo[]>().ToConstant(new IFoo[0]); // ToConstant() is just an example } } public class Program { private static void Main(string[] args) { var kernel = new StandardKernel(new MyModule()); var bar = kernel.Get<Bar>(); } } When I try to run the program I get the following exception. Error activating IFoo No matching

Inject a dependency into a custom model binder and using InRequestScope using Ninject

怎甘沉沦 提交于 2019-11-27 15:37:54
I'm using NInject with NInject.Web.Mvc. To start with, I've created a simple test project in which I want an instance of IPostRepository to be shared between a controller and a custom model binder during the same web request. In my real project, I need this because I'm getting IEntityChangeTracker problems where I effectively have two repositories accessing the same object graph. So to keep my test project simple, I'm just trying to share a dummy repository. The problem I'm having is that it works on the first request and that's it. The relevant code is below. NInjectModule: public class

How do I handle classes with static methods with Ninject?

◇◆丶佛笑我妖孽 提交于 2019-11-27 15:03:25
How do I handle classes with static methods with Ninject? That is, in C# one can not have static methods in an interface, and Ninject works on the basis of using interfaces? My use case is a class that I would like it to have a static method to create an unpopulated instance of itself. EDIT 1 Just to add an example in the TopologyImp class, in the GetRootNodes() method, how would I create some iNode classes to return? Would I construct these with normal code practice or would I somehow use Ninject? But if I use the container to create then haven't I given this library knowledge of the IOC then

Ninject Binding Attribute to Filter with Constructor Arguments

江枫思渺然 提交于 2019-11-27 14:41:15
I read as many answers as I could for this, but they seem to fall short of one detail. The trouble is when binding an action filter (with a service injected by controller) to a corresponding attribute, I've been unable to figure out how to pass parameter/property values from the attribute to its bound filter. Below is the code, and below that my intended fake-code: Filter & Attribute public class AuthorizationFilter : IAuthorizationFilter { private readonly IAuthorizationService _authorizationService; private readonly UserRoles _requiredRoles; // Enum public AuthorizationFilter

MVC 4 Web Api Controller does not have a default constructor?

帅比萌擦擦* 提交于 2019-11-27 14:41:14
问题 Here is the trace: <Error> <Message>An error has occurred.</Message> <ExceptionMessage> Type 'ProjectName.Web.Api.Controllers.ContinentsController' does not have a default constructor </ExceptionMessage> <ExceptionType>System.ArgumentException</ExceptionType> <StackTrace> at System.Linq.Expressions.Expression.New(Type type) at System.Web.Http.Internal.TypeActivator.Create[TBase](Type instanceType) at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.GetInstanceOrActivator