ninject

Generic repository, DI, Aggregation Roots

我怕爱的太早我们不能终老 提交于 2019-12-07 19:34:47
问题 Having a generic repository like public class Repository<T> where T: Entity<T> { /*anything else*/ } should concrete repositories per agregation root like class ProductRepository : Repository<Product> { } class CategoryRepository : Repository<Category> { } be created? Also how do I use DI ( Ninject ) with generic implementation of repository. Samples are apreciated! Thanks! 回答1: I see a lot of misuse of generics in the questions in SO and while it does not necessarily refer to your question

Is it a good practice to pass the Ninject kernel around?

北战南征 提交于 2019-12-07 19:05:47
问题 I'm writing a small framework that executed a couple of tasks. Some om the tasks needs specific properties which are injected through Ninject. Let's say that I have the following constructor in my base class that represents a single Task: protected DDPSchedulerTask(ILogger logger, List<string> platforms, IBackOfficeDataStore backOfficeDataStore, ICommonDataStore commonDataStore) { _logger = logger; _platforms = platforms; _backOfficeDataStore = backOfficeDataStore; _commonDataStore =

Dependency Injection of a service usage inside the global.asax

走远了吗. 提交于 2019-12-07 18:41:44
问题 I'm using Ninject to do dependency injection. I have a userService in which I need to access from the global.asax file. How do I dependency inject this? private IUserService userService;//<--this protected void Application_PostAuthenticateRequest(Object sender, EventArgs e) { HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName]; if (authCookie != null) { FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value); var identity = new

How to avoid having BAL dependent on DAL due to DI Container binding requirements?

淺唱寂寞╮ 提交于 2019-12-07 18:19:48
问题 My application consists of three projects. Core, DAL and BAL. Core contains Domain objects (Customer, Order, Product). It also contains basic IRepository interface IRepository <T>. DAL contains EntityFramework specific stuff. It also contain Concrete Repositories ( CustomerRepository, OrderRepository, ProductRepository). I added these concrete repositories here as they depend on DbContext (which is EF Specific) Now my BAL should only have dependency on Core and no dependency on DAL. I have

Ninject Runtime Exception occuring frequently - System.InvalidOperationException: Collection was modified; enumeration operation may not execute

耗尽温柔 提交于 2019-12-07 17:31:52
问题 I am using Ninject 2.2.1.0 with Ninject.Web 2.2.0.0 in a webforms application. I am getting daily error reports of the following... System.InvalidOperationException: Collection was modified; enumeration operation may not execute. at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) at System.Collections.Generic.List 1.Enumerator.MoveNextRare() at System.Collections.Generic.List 1.Enumerator.MoveNext() at System.Linq.Enumerable.WhereSelectListIterator 2.MoveNext()

not able to make ninject work in asp.net mvc4 web application

有些话、适合烂在心里 提交于 2019-12-07 17:07:32
问题 I am learning how to use Ninject in my asp.net MVC 4 web application. I am not sure I have got the concepts right. This is what I did. 1) Installed Ninject.MVC3 using Manage NuGet 2) Added the following code in NinjectWebCommon.cs(this file was added automatically by Nuget in App_start folder) private static void RegisterServices(IKernel kernel) { **kernel.Bind<IProductRepository>.To<ProductRepository>;** } 3) Controller Code Public Class ProductController Inherits System.Web.Mvc.Controller

Ninject 3.0 MVC kernel.bind error Auto Registration

半城伤御伤魂 提交于 2019-12-07 16:39:16
问题 Getting and error on kernel.Bind( scanner => ... "scanner" has the little error line under it in VS 2010. Cannot convert lambda expression to type 'System.Type[]' because it is not a delegate type Tyring to Auto Register like the old kernel.scan in 2.0. I can not figure out what i am doing wrong. Added and removed so many Ninject packages. completely lost, getting to be a big waste of time. using System; using System.Web; using Microsoft.Web.Infrastructure.DynamicModuleHelper; using Ninject;

Error activating IInterceptor… only through COM?

痴心易碎 提交于 2019-12-07 16:25:10
问题 TL;DR: Kernel.Get<T> works when called from a .net/WPF app, but blows up with an inner ActivationException (inside a TargetInvocationException ) when called from a VB6 app. WTH? This is a bit of a follow-up on this question where I configured an abstract factory with Ninject conventions, in such a way that I never need to actually implement one, the Ninject factory extension takes care of generating one on-the-fly. This worked beautifully... until I needed to run my library from VB6 code.

DbContext with Ninject ADO.NET

让人想犯罪 __ 提交于 2019-12-07 15:38:26
I am working on a big project that 80% completed (Some features need to be implemented though).But recently we discovered that the project doesn't allow concurrent requests (I mean multiple users request to same repository). Sometime we get null referece & sometimes "Executed can not open available connection , connection state is closed" etc. Our source code is strongly restricted outside of the world. Here is some code.Let me know if there is any architectural problem, as architectural guys left company. It's using ninject 3.0. I already used InRequestScope() for all manager's repositories

Passing parameters to a WCF ServiceHost type with Ninject 2

随声附和 提交于 2019-12-07 15:37:44
问题 I want to use a Ninject.Wcf extension to create a parametrized service host instance. For example I have a class MyWCFHandler with the only following constructor: public MyWCFHandler(UserManager manager) { _manager = manager; } But when I write var myServiceHost = new ServiceHost(typeof(MyWCFHandler)); I have no way to pass the dependency object to a constructor. I don't want to mess with the custom ServiceHost like offered in How do I pass values to the constructor on my wcf service? I