ninject

OWIN DbContext and a single DbContext for all of my Repositories

匆匆过客 提交于 2020-01-04 19:38:56
问题 I am building a ASP.NET MVC application. I'm new to the whole Repositories/Unit Of Work patterns. I'm part way through implementing a generic repository for my EF objects. I realise that there is an issue with ensuring that you only have a single DbContext per Http request... I'm pretty sure that I can achieve this by creating an instance using OWIN. /// <summary> /// Configures OWIN /// </summary> /// <param name="app"></param> public void Configuration(IAppBuilder app) { // Create instance

Ninject Property Injection in WebAPI custom ExceptionFilterAttribute Not Working

南笙酒味 提交于 2020-01-04 14:31:13
问题 I am trying to use Ninject to inject an EventLogger instance into a custom ExceptionFilterAttribute. Whenever I run the code, the EventLogger instance is null. I have implemented an IFilterProvider to resolve dependencies in a similar manner for my custom AuthorizationFilterAttribute, and that works fine. Any ideas? Not Working public class ErrorHandlingAttribute : ExceptionFilterAttribute { [Inject] public IEventLogger EventLogger { get; set; } public override void OnException

Ninject.Web.MVC4 disposes my DbContext exactly once

心已入冬 提交于 2020-01-04 14:12:31
问题 There are a half dozen identical questions, I know. I've followed the advice of their answers, and I'm still stuck. I've used NuGet to install Ninject.Web.MVC4 and added my bindings to NinjectWebCommon.RegisterServices . I've manually added the following to system.web/httpModules <httpModules> <add name="OnePerRequestModule" type="Ninject.OnePerRequestModule"/> </httpModules> I've wrapped my bindings in a Ninject GlobalKernelRegistrationModule<OnePerRequestHttpModule> My DataContext: public

ninject inject iunitofwork to repository scoped attribute

风流意气都作罢 提交于 2020-01-04 11:08:14
问题 Let me start with my current setup, and then explain what I am trying to achieve. We are using NHibernate and trying to implement the IRepository/IUnitOfWork pattern with Ninject. It should ideally work generically for whatever application is using the code, whether is ASP.Net, WCF or something else. IUnitOfWork public interface IUnitOfWork { object Add(object obj);//all other supported CRUD operations we want to expose void Commit(); void Rollback(); } UnitOfWork public class UnitOfWork :

Setting up Ninject with the new WCF Web API

巧了我就是萌 提交于 2020-01-03 08:44:08
问题 So I've been playing around with the latest release of the WCF Web API and decided I wanted to dive into implementing Ninject with it. Based off what I've read I need to implement the interface IResourceFactory which demands the following methods: public object GetInstance(System.Type serviceType, System.ServiceModel.InstanceContext instanceContext, System.Net.Http.HttpRequestMessage request); public void ReleaseInstance(System.ServiceModel.InstanceContext instanceContext, object service); So

Ninject assembly does not match referenced assembly

拥有回忆 提交于 2020-01-03 07:52:20
问题 Setup: ASP.NET MVC3 Ninject v2.2.1.4 Ninject v3.0.0.15 Ninject.MVC3 v3.0.0.6 Ninject.Web.Common v3.0.0.7 Using NuGet, my UnitTest project references Ninject v2.2.1.4 My Web Project references Ninject v3.0.0.15, Ninject.MVC3 and Ninject.Web.Common Problem: With win explorer open at the bin folder of my web project, I build my solution and I can see Ninject v2.2.1.4 copied into the bin directory of my web project. And then being replaced by Ninject v3.0.0.15. When i hit F5 to debug, Ninject.dll

Ninject assembly does not match referenced assembly

空扰寡人 提交于 2020-01-03 07:52:12
问题 Setup: ASP.NET MVC3 Ninject v2.2.1.4 Ninject v3.0.0.15 Ninject.MVC3 v3.0.0.6 Ninject.Web.Common v3.0.0.7 Using NuGet, my UnitTest project references Ninject v2.2.1.4 My Web Project references Ninject v3.0.0.15, Ninject.MVC3 and Ninject.Web.Common Problem: With win explorer open at the bin folder of my web project, I build my solution and I can see Ninject v2.2.1.4 copied into the bin directory of my web project. And then being replaced by Ninject v3.0.0.15. When i hit F5 to debug, Ninject.dll

How to do Setup of mocks with Ninject's MockingKernel (moq)

五迷三道 提交于 2020-01-03 07:38:09
问题 I'm having a really hard time trying to figure how I can do .SetupXXX() calls on the underlying Mock<T> that has been generated inside the MockingKernel . Anyone who can shed some light on how it is supposed to work? 回答1: You need to call the GetMock<T> method on the MoqMockingKernel which will return the generated Mock<T> on which you can call your .SetupXXX()/VerifyXXX() methods. Here is an example unit test which demonstrates the GetMock<T> usage: [Test] public void Test() { var

EF4.0, repositories, and Ninject 2

蓝咒 提交于 2020-01-02 23:35:12
问题 This is in continuation of two ongoing problems I'm facing: Problems trying to attach a new EF4 entity to ObjectContext while its entity collection entities are already attached and EF4.0 - Is there a way to see what entities are attached to what ObjectContext during debugging? I'm using this space to ask another somewhat complicated question, and I don't want to make a huge, ultra long question out of my other threads. So, a quick rundown: I have incoming form data which is bound to a DTO. I

How to store Ninject Kernel in an ASP.NET Application?

落花浮王杯 提交于 2020-01-02 10:02:43
问题 I'm really confused about small, partial, one-file examples where there's a Ninject kernel everywhere without showing how to really get to that kernel in the application. (1) Should we instantiate one Kernel and keep it in "static" context? Or should we instantiate a different one on every request (*in Application_BeginRequest*) (2) If it is "kernel per request", then why Initialize() method of the NinjectWebCommon.cs ( gets when you install the NuGet package ) is called on Application_Start