ninject

Ninject.ActivationException thrown only on first web request (WebAPI 2, OWIN 3, Ninject 3)

主宰稳场 提交于 2019-11-27 03:03:43
问题 I am attempting to create a "barebones" Web API project that uses OWIN middleware, Ninject Depencency Injection, and ultimately to be hosted in IIS. I have followed instructions found in an article, "Befriending ASP.NET Web.API2, OWIN and Ninject," here: http://www.alexzaitzev.pro/2014/11/webapi2-owin-and-ninject.html, except I used an empty Web Application Project, and did not tick the "Include Web API references and folders" when creating the project. When I fire up the new API and make a

Ninject injection based on a route data value

依然范特西╮ 提交于 2019-11-27 02:56:53
问题 We've got an ASP.NET MVC application, that has a number of different areas. There are 2 areas that use the same C# classes from our service layer, but target different underlying data. I want these services to get different dependencies based on a value in the route data. It's hard to explain, and I'm paraphrasing my class/area names. To illustrate: When the 'Code' is in the route data, I want to get different dependencies injected to when it is not present. I understand there is the .When()

Making Entity framework implement an interface

我是研究僧i 提交于 2019-11-27 02:31:11
问题 I want to use IoC with Entity framework and Ninject. I figure I need the Generated Entity classes to implement an interface, ICRUD. There's a walkthrough that shows how to force Entity framework to implement an interface. I followed the directions and my EntityObjectCodeGenerator.cs file indeed shows "ICrud", but doesn't implement the interface. I don't see any subclasses under EntityObjectCodeGenerator.tt as the article says I'm supposed to. I get error 'BugnetMvc.Models.BugNetEntities' does

Ninject Intercept any method with certain attribute?

若如初见. 提交于 2019-11-27 02:19:24
问题 How can I get Ninject.Extensions.Interception to basically let me bind a specific interceptor to any method that has an attribute... psudocode: Kernel.Intercept(context => context.Binding.HasAttribute<TransactionAttribute>()) .With<TransactionInterceptor> With a class like: public SomeClass { [TransactionAttribute] public void SomeTransactedMethod() { /*do stuff */ } } 回答1: Assuming that you are using Ninject.Extensions.Interception this should do the trick public class TransactionInterceptor

Lazy Loading with Ninject

安稳与你 提交于 2019-11-27 01:59:40
问题 I'm evaluating ninject2 but can't seem to figure out how to do lazy loading other than through the kernel. From what I can see that kind of defeats the purpose of using the [Inject] attributes. Is it possible to use the InjectAttribute but get lazy loading? I'd hate to force complete construction of an object graph every time I instantiated an object. To specify, I'm really just curious about the performance. 回答1: Update: My original answer was written before the .NET Framework 4 was released

IoC (Ninject) and Factories

做~自己de王妃 提交于 2019-11-27 01:48:55
问题 If I have the following code: public class RobotNavigationService : IRobotNavigationService { public RobotNavigationService(IRobotFactory robotFactory) { //... } } public class RobotFactory : IRobotFactory { public IRobot Create(string nameOfRobot) { if (name == "Maximilian") { return new KillerRobot(); } else { return new StandardRobot(); } } } My question is what is the proper way to do Inversion of Control here? I don't want to add the KillerRobot and StandardRobot concretes to the Factory

SignalR 2 Dependency Injection with Ninject

房东的猫 提交于 2019-11-27 01:38:21
问题 I have an existing MVC application that is using Dependency Injection with Ninject. I installed the Ninject.MVC3 nuget package and it creates a class called NinjectWebCommon in my App_Start, which completely isolates the kernel and registers all of my bindings: public static void Start() { DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule)); DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule)); bootstrapper.Initialize(CreateKernel); } private static IKernel

Lazy Dependency Injection

北战南征 提交于 2019-11-27 01:35:18
问题 I have a project where the Ninject is used as IoC container. My concern is that a lot of classes have such kind of constructors: [Inject] public HomeController( UserManager userManager, RoleManager roleManager, BlahblahManager blahblahManager) { _userManager = userManager; _roleManager = roleManager; _blahblahManager = blahblahManager; } What if I don't want to have all instances of these classes at once? The way, when all this classes are wrapped by Lazy<T> and passed to constructor is not

NHibernate, and odd “Session is Closed!” errors

和自甴很熟 提交于 2019-11-27 00:56:50
问题 Note: Now that I've typed this out, I have to apologize for the super long question, however, I think all the code and information presented here is in some way relevant. Okay, I'm getting odd "Session Is Closed" errors, at random points in my ASP.NET webforms application. Today, however, it's finally happening in the same place over and over again. I am near certain that nothing is disposing or closing the session in my code, as the bits of code that use are well contained away from all

Error Handling in asp.net mvc 3

陌路散爱 提交于 2019-11-27 00:42:44
问题 Is there a built in or a proper way to handle errors in asp.net mvc 3? This is what I want to do: If the application crashes, or throws an error, it goes to a specific error page. I can throw my own error from the controller action. (and it goes to an error page). I found the following ways: I see there is a long way to do it here. (for v1 and v2 but also applies to v3). Using errorhandle attribute here. How do I handle this the proper way? If the solution is similar or is like #1 in the list