ninject

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

大城市里の小女人 提交于 2019-12-06 05:09:10
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() at Ninject.Infrastructure.Language.ExtensionsForIEnumerableOfT.Map[T](IEnumerable 1 series, Action`1

Ninject - The resource cannot be found

半城伤御伤魂 提交于 2019-12-06 04:50:26
问题 I get error The resource cannot be found. When I try to implement Ninject in my MVC-3 application. The problem appears to be coming from Global.asax during CreateKernel() #region Inversion of Control protected override IKernel CreateKernel() { return Container; } static IKernel _container; public static IKernel Container { get { if (_container == null) { _container = new StandardKernel(new SiteModule()); } return _container; } } internal class SiteModule : NinjectModule { public override void

Dependency Injection of a service usage inside the global.asax

大兔子大兔子 提交于 2019-12-06 04:40:50
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 CustomIdentity(authTicket); string[] userRoles = userService.GetRolesForUser(identity.Name);// <-- Used here. var

Interception with Ninject. Fails to load IProxyRequestFactory

本小妞迷上赌 提交于 2019-12-06 04:38:56
问题 I'm learning to use Ninject and Interceptor pattern. I have the following interceptor. public class MyInterceptor:IInterceptor { public void Intercept(IInvocation invocation) { Console.WriteLine("Pre Execute: " + invocation.Request.Method.Name); foreach (var param in invocation.Request.Arguments) { Console.WriteLine("param : " + param); } invocation.Proceed(); Console.WriteLine("Post Execute: " + invocation.Request.Method.Name); Console.WriteLine("Returned: " + invocation.ReturnValue); } }

Get ninject factory extension to allow factory parameters be passed to dependencies

此生再无相见时 提交于 2019-12-06 04:36:33
问题 Using the Ninject Factory extension, you can automatically generate factories, and let the factory pass parameters to the class' constructor. The following test passes: public interface IBar { int Foo { get; } } public class Bar : IBar { int _foo; public Bar(int foo) { _foo = foo; } public int Foo { get { return _foo; } } } public interface IBarFactory { IBar CreateTest(int foo); } [Test] public void ExecuteTest() { var kernel = new StandardKernel(); kernel.Bind<IBar>().To<Bar>(); kernel.Bind

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

久未见 提交于 2019-12-06 04:24:59
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 Private _rProduct As IProductRepository ' ' GET: /Product Sub ProductController(ProductRepository As

Ninject in an Action Filter

二次信任 提交于 2019-12-06 04:15:56
I have created a custom Action Filter and am binding it with Ninject's BindFilter method: public class ExtendModelAttribute : FilterAttribute {} public class ExtendModelFilter : IActionFilter { private IKernel kernel; public ExtendModelFilter(Func<IKernel> kernel) { this.kernel = kernel; } public void OnActionExecuted(ActionExecutedContext filterContext) { // TODO: } public void OnActionExecuting(ActionExecutingContext filterContext) { } } I am binding my filter like so: kernel.BindFilter<ExtendModelFilter>(FilterScope.Action, 0).WhenActionMethodHas<ExtendModelAttribute>(); Everything so far

SignalR, WebAPI and MVC sharing the same dependency resolver kernel

对着背影说爱祢 提交于 2019-12-06 03:54:10
I have an ASP.NET MVC app with SignalR and WebAPI . The app uses Ninject for dependency injection, but apparently SignalR and WebAPI are getting different kernels, so it fails to share a singleton object that should be shared for all the application. I can see clearly in the log how an instance is created when SignalR gets a connection request, and other when WebAPI gets a request. I want to have the same Ninject kernel shared among these three elements, so I can have unique singletons. This is what I have done so far: The first thing I have done is creating a NinjectModule declaring the

Passing parameters to a WCF ServiceHost type with Ninject 2

丶灬走出姿态 提交于 2019-12-06 03:49:19
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 decided to go with the Ninject way, but not able to fully understand how to act in my situation. Here is

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

自古美人都是妖i 提交于 2019-12-06 03:42:40
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 added a dependency on NInject in this project. However, I still need to tell Ninject that it should