ninject

ASP.NET MVC 3 Application using Ninject, Entity Framework 4 Code-First CTP 5, Patterns

巧了我就是萌 提交于 2019-12-03 01:23:24
问题 I've tried to build some base project with above technologies. I wanted maximum flexibility and testability so I tried to use patterns along the way to make this as a base for future projects. However, it seem something is wrong or whatever and I really need help here. So i have two questions : Is there anything wrong with my current code? I've applied patterns correctly? Any suggestions or recommendation that would lead me in the right direction? Why do this code actually connect to the

NInject: Where do you keep your reference to the Kernel?

心已入冬 提交于 2019-12-03 01:19:50
问题 I'm using NInject on a new web application and there are two things that are unclear to me: Don't I need to keep a reference to the Kernel around (Session/App variable) to insure that GC doesn't collect all my instances? For example, if I specify .Using() and then the Kernel object gets collected, aren't all my "singletons" collected as well? If I do need keep a reference to a Kernel object around, how do I allow the arguments passed in to WithArguments() to change or is that not possible.

Dependency Injection in WinForms using Ninject and Entity Framework

感情迁移 提交于 2019-12-03 01:13:55
问题 I am currently working on a project where we are converting our old DataSet, Stored Procedure WinForm application to use Entity Framework so new websites can access the same object model and repositories. Anyway, I am trying to implement Dependency Injection into the Forms so that we can use mocked Repositories for unit testing. I am using Ninject for the the simple reason I have used it before in MVC websites, however trying to implement this in the WinForm application is proving to be

Ninject vs Unity for DI [closed]

老子叫甜甜 提交于 2019-12-03 00:29:03
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago . We are using ASP.net MVC. Which of these is the best DI framework Ninject or Unity and why? 回答1: Last time I looked at either of them I found Ninject slightly better. But both have their drawbacks. Ninject has a better fluent-configuration scheme. Unity seems to rely mostly

How to get implementing type during Ninject dependency resolve?

纵饮孤独 提交于 2019-12-02 21:29:48
问题 I use Log4net for logging and I have a lot of objects with an ILog dependency. These dependencies are injected just as the others. I would like to stick to the Log4net logger naming convention so the logger injected to an instance is named after the type of the instance. I have been using the following binding for ILog: Bind<ILog>().ToMethod(ctx => LogManager.GetLogger(ctx.Request.ParentRequest == null ? typeof(object) : ctx.Request.ParentRequest.Service) ); Which is against the naming

Ninject and configuration

坚强是说给别人听的谎言 提交于 2019-12-02 21:17:22
问题 I used to use Castle as an IoC but I had a problem using Nhibernate/Castle(IoC) in the same project so i moved to Ninject. Now to get to the question, I have this class: class CustomModule : NinjectModule { public override void Load() { Bind<Interfaces.ICafe>().To <Concrete.Tea>(); } } Concrete is a separate project and Interfaces.ICafe is a different project. With Castle I used to give a developer the interfaces DLL and ask him to implement a new concrete implementing that interface and then

Avoiding Service Locator Antipattern with legacy app not designed for IOC

泄露秘密 提交于 2019-12-02 20:59:28
I have read often that Service Locators in IOC are an anti-pattern . Last year we introduced IOC (Ninject specifically) to our application at work. The app is legacy, it's very big and it's fragmented. There are lots of ways a class, or a chain of classes can get created. Some are created by the web framework (which is custom), some are created by nHibernate. Lots are just scattered around in weird places. How would we handle the different scenarios and not come up with something thats not at least ServiceLocatorish and not end up with different kernels in different places (scopes like

Dependency Injection in a 3 layer asp.net mvc application

孤者浪人 提交于 2019-12-02 20:50:04
I have a 3 layer application and the layers are: Web: Presentation Layer (ASP.NET MVC) --> only sees BLL BLL: Business Logic Layer --> only sees DAL DAL: Data Access Layer So the Web layer doesn't know anything about my DAL layer. I have repository interfaces and concrete classes in my DAL , which are used in BLL layer in business logic classes. The question is, in order to decouple DAL and BLL , how do I setup Ninject to inject my repository implementations to the BLL layer? The same question is for Web layer and BLL layer, I have interfaces and implementations on BLL which I use them in Web

Ninject.MVC3, Nuget, WebActivator oh my

巧了我就是萌 提交于 2019-12-02 20:39:39
I want to setup Ninject to do a simple test, as well as demonstrate the ease-of-setup using Nuget. I want to resolve a sample service. public interface ITestService { string GetMessage(); } public class TestService : ITestService { public string GetMessage() { return "hello world"; } } I run the NuGet Install-Package NinjectMVC3 .... it nicely drops NinjectMVC3.cs into my App_Start folder, decorated with some WebActivator attributes to get it all loaded. Next I add my binding in the NinjectMVC3.RegisterServices method: private static void RegisterServices(IKernel kernel) { kernel.Bind

Using Ninject with Asp.NET Web API Beta ApiController

房东的猫 提交于 2019-12-02 19:38:48
I'm stuck. I was using the method outlined here for wcf web api p6 Ninject working with WCF Web API Preview 5 , however things are quite a bit different with the mvc implementation in the beta. There is a good article here http://www.asp.net/web-api/overview/extensibility/using-the-web-api-dependency-resolver that talks about building your own custom dependency resolver, however i would like to use the same implementation i'm using for my mvc view controllers...e.g. Ninject. I've tried a few things based on the IoC Unity example in the article too, but nothing has panned out yet. Any help