ninject

Ninject 3.0 MVC kernel.bind error Auto Registration

蓝咒 提交于 2019-12-06 01:53:29
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; using Ninject.Web.Common; //using Ninject.Extensions.Conventions; using Ninject.Web.WebApi; using

How do you use method injection with Ninject?

 ̄綄美尐妖づ 提交于 2019-12-06 01:23:40
问题 I have a class which needs to use an IRepository for one method in it's class. Ideally, I would like to avoid having to resolve this dependency into the class's constructor, and so I found method level injection in Ninject and was wondering how this works? I understand how to set it up. What I'm confused about is how to call it? Example: class SomeClassThatUsesRepository { [Inject] public void QueryForSomeStuff(IRepository repository) { //do some stuff } } My problem is how do I call this

Castle Windsor Typed Factory Facility equivalents

与世无争的帅哥 提交于 2019-12-05 22:59:45
问题 do any other .NET IoC containers provide equivalent functionality to the typed factory facility in Castle Windsor? e.g. if I am using an abstract factory pattern in a WPF application: public class MyViewModel { private IAnotherViewModelFactory factory; public void ShowAnotherViewModel() { viewController.ShowView(factory.GetAnotherViewModel()); } } I don't want to have to create a manual implementation of IAnotherViewModelFactory for every type of ViewModel I wish to show, I want the container

Building a WinForms Application using MVC and Ninject as IoC Container

随声附和 提交于 2019-12-05 21:41:14
I am having to re-write a large WinForms application and I want to use MVC to allow increased testing capability etc. I want to also adopt Ninject as my IoC container as it is lightweight, fast and will increase the exstensibility of my application going forward. I have done a great deal of reading and I have managed to make a start on the arcitecture of this new application. However, I am not sure i have the right idea when using Ninject. The code... Starting with Program.cs and related classes... static class Program { [STAThread] static void Main() { FileLogHandler fileLogHandler = new

When should one use Kernel.BeginBlock() in Ninject.MVC3

£可爱£侵袭症+ 提交于 2019-12-05 21:34:41
I'm using Ninject.MVC3 with WebAPI. Originally, I was using the implementation of NinjectResolver and NinjectScope as outlined here ,i.e. using _kernel.BeginBlock() , I noticed that BeginBlock() gets invoked on each call to the Controller. On load testing the controller (over several hundred invocations) I noticed that the memory consumption of w3wp increased significantly (upwards of 1.4 gigs on high load) and the GC would never reclaim any memory. Per this SO post , the kernel should not be disposed and BeginBlock() should not be used . Following which I updated the Resolver and Scope like

No parameterless constructor object defined

笑着哭i 提交于 2019-12-05 19:44:59
I know that this is a duplicate question but i can't find answer to my error. I'm trying to show a list of my rooms saved in database but i get next error: Server Error in '/' Application. No parameterless constructor defined for this object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.MissingMethodException: No parameterless constructor defined for this object. Source Error: An unhandled exception was generated

Ninject different behaviour between Kernel.Get and Constructor Injection

我只是一个虾纸丫 提交于 2019-12-05 18:49:09
What do I have: public interface IBla { } public class Bla1 : IBla { } public class Bla : IBla { } public class Consumer { private readonly IBla[] _array; public Consumer(IBla[] array) { _array = array; } } public static class NinjectExtensions { public class BindListExpression<TElement> { private readonly IKernel _kernel; private readonly List<Type> _types = new List<Type>(); public BindListExpression(IKernel kernel) { _kernel = kernel; } public BindListExpression<TElement> ImplementedBy<T>() where T : TElement { var type = typeof(T); _kernel.Bind<T>().To(type); _types.Add(type); return this;

Ninject problem binding to constant value in MVC3 with a RavenDB session

主宰稳场 提交于 2019-12-05 18:28:32
I've seen a lot of different ways of configuring Ninject with ASP.NET MVC, but the implementation seems to change slightly with each release of the MVC framework. I'm trying to inject a RavenDB session into my repository. Here is what I have that's almost working. public class MvcApplication : NinjectHttpApplication { ... protected override void OnApplicationStarted() { base.OnApplicationStarted(); AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); } protected override IKernel CreateKernel() { return new StandardKernel(new

Actionfilter Injection in ASP.NET MVC 5

ぃ、小莉子 提交于 2019-12-05 16:52:48
I have a simple filter. public class IsAdmin : ActionFilterAttribute, IAuthenticationFilter { private string _roleName; IBusinessIdentity _identity; public IsAdmin(string roleName, IBusinessIdentity identity) { this._roleName = roleName; this._identity = identity; } public void OnAuthentication(AuthenticationContext filterContext) { } public void OnAuthenticationChallenge(AuthenticationChallengeContext filterContext) { if (!_identity.Roles.Contains(_roleName)) filterContext.Result = new HttpUnauthorizedResult(); } } I am using Ninject. Here is my controller. I'm trying to get the injected

Dependency injection and life time of IDisposable objects

百般思念 提交于 2019-12-05 16:16:18
I am trying to develop a library using dependency injection approach (with Ninject) and I am having some kind of confusion likely because of my incorrect design. In summary, my design approach is A parent object has a common object. A parent object uses some variable number of child objects. All child objects should use the very same common object instance with their parent object Here is a simple model of my problem domain. interface IParent : IDisposable { void Operation(); } interface ICommon : IDisposable { void DoCommonThing(); } interface IChild1 { void DoSomething(); } interface IChild2