Questions tagged [ninject]

1

votes
2

answer
57

Views

How do I provide extra parameters with Ninject?

I need to auto-resolve dependencies of my windows form. The only problem is my forms constructor expects an integer value as well. Please have a look at the implementation in the code section. //Ninject bindings public class Bindings : NinjectModule { public override void Load() { Bind().To(); Bind(...
void
1

votes
1

answer
282

Views

Xamarin forms app throws a null exception when creating StandardKernel

I created with VS2017 a cross-platform App(Xamarin Forms) with the template set to Blank App, Platform Android, UI Tech Xamarin.Forms, Code Sharing .NET Standard. All builds and runs and displays 'Welcome to Xamarin Froms'. I added the Portable.Ninject package to both the .NET standard PCL project a...
Big Kevin
1

votes
2

answer
499

Views

Dependency Injection using ninject not working

My goal is simply this: I want the already existent instance of class 'MainWindowVM' (implementing IMainWindowVM) to be injected into class 'StaticTestsResultsViewModel'. I do not(!) want a new instance of class 'MainWindowVM' to be instantiated. Instead, I want the already existent instance of this...
steady_progress
1

votes
0

answer
40

Views

Could Not Load Type From Assembly on unused package version

I have a C# project that I just pulled down from version control on a new machine. I have all the dependencies installed in the project and when I try to run it I get to my dependency injection initialization (ninject) an System.TypeLoadException error on an internal library. The error says that it...
loganhuskins
1

votes
0

answer
48

Views

Ninject Xamarin.Forms Exception While Instantiating StandarKernel

I'm getting an exception when trying to build my Ninject instance: System.InvalidOperationException: Error loading Ninject component IBindingPrecedenceComparer No constructor was available to create an instance of the registered implementation type BindingPrecedenceComparer. I tried to instantiate i...
MJ33
1

votes
2

answer
42

Views

ninject setter injection in attribute routing Web API

I am trying ninject.mvc5 to do DI on Web API application. I added ninject and ninject.mvc5 in my main MVC project. I added one class library for Web API controllers and using attribute routing. I was trying to inject an object using Setter Injection on both MVC project and class library. Object prop...
Manik_trs
1

votes
1

answer
202

Views

How to use Ninject.Web.Common.OwinHost 3.3.0?

Who can tell me about Ninject.Web.Common.OwinHost? I'm using this manual https://github.com/ninject/Ninject.Web.Common/wiki/Setting-up-a-OWIN-WebApi-application, but it looks like it's out of date, because UseNinjectWebApi method doesn't exists. I'm trying to do this instead: public void Configurati...
imported_lis
1

votes
0

answer
83

Views

How do I setup Ninject to work with log4net?

I have some basic Web API code that uses Ninject. Till now I wasn't really logging anything but just sending BadRequest object in case something is wrong. With that code working fine, I want to add some logging (could be just info, errors or debug if need be) and I was using this article as my guide...
Subrato M
1

votes
0

answer
48

Views

How can I check if a service has been instantiated via Ninject?

I'm using Ninject in my intergration tests to create instances of stuff my tests need. I want to run some clean up code in the Tear Down method of the test, but only if a particular service has been instantiated via the Kernel. I'm looking for something similar to this: var kernel = new StandardKern...
BG100
1

votes
1

answer
122

Views

Can I use IoC container without having interfaces?

I have an application consisted of maybe more than 80 Web-Api controllers.Each one has the following Constructor definition: public class AlertsController : ApiController { IAlertsService _alertsService; public AlertsController(IAlertsService alertsService) { _alertsService = alertsServic...
user_1856538_
1

votes
1

answer
46

Views

Confusion over using Ninject using asp.net c#

after lots of efforts in DI i could finally figure out the basics,but as long as i know up to now,instantiating or using NEW key word in the controller means we are still not satisfying the DI,i have created a small project to point out my problem: public interface IOperations { int mul(int a, int...
mrslt
1

votes
1

answer
112

Views

System.InvalidOperationException when setting up constructor injection

I am trying to inject a constructor parameter using Ninject: private void AddBindings() { //_kernel.Bind().ToConstructor(x => new RestClient('http://localhost:49780/api/ProductApi')); _kernel.Bind().ToConstructor(x => new RestClient(ConfigurationManager.AppSettings['ProductsApiUrl'])); } However I g...
Backwards_Dave
1

votes
1

answer
99

Views

Can I get instance dynamically by type or class name using Ninject

void Start () { IKernel nKernel = new StandardKernel(); nKernel.Bind().To(typeof(Dog)).Named('Dog'); nKernel.Bind().To(typeof(Cat)).Named('Cat'); IAnimal animalInst = nKernel.Get('Dog'); Debug.LogError($'{animalInst.Name}'); IAnimal animalInst2 = nKernel.Get('Cat'); Debug.LogError($'{animalInst.Nam...
min kyu Park
1

votes
0

answer
73

Views

Constructor Injection into a custom attribute

I'm trying the following: custom attribute: public class AuthorizeUserAttribute : AuthorizeAttribute { private readonly IUserCodeService _userCodeService; public AuthorizeUserAttribute(IUserCodeService userCodeService) { _userCodeService = userCodeService; } On my controller I use it like: [Authoriz...
Kris van der Mast
1

votes
0

answer
217

Views

Does thread scope in ninject creates new dbcontext on every thread call

I have configured ninject in wep api as below. I have created two kernel objects, one in request scope and another in thread scope: var requestKernel = new StandardKernel(); requestKernel.Bind().ToConstructor(ctx => new GlobalDbContext(Configuration.GlobalDbContext)).InRequestScope(); var threadKern...
Raja Kondla
1

votes
1

answer
201

Views

How to use multi threading with entity framework in web api 2

We are going to create a product from our existing application. Our existing application is using Entity framework 6, Web API 2, ninject. So instead of creating a new design and using a new technologies, we are using same technologies i.e,Entity framework 6, Web API 2, ninject. There will be heavy d...
Raja Kondla
1

votes
2

answer
107

Views

MVC 5 with Ninject and EF Core, Context throws exception after one query

I am trying to use EF Core in our ASP.Net MVC 5 web application using Framework 4.6.1. We are using Ninject for dependency injection. I am injecting the Context in the DAL layer. I am successful a performing a single query but the context throws the following exception when the next query is run No...
Thomas927
1

votes
0

answer
40

Views

Use log4net with Ninject

I have a console application, with Quartz, Ninject and log4net. My question is I can't understand why this code works fine (logs working): kernel.Bind() .ToConstant(LogManager.GetLogger(typeof(Program))) .InSingletonScope(); But when I try to use with context, it is not working (logs not working emp...
1

votes
0

answer
23

Views

Changing connection string after Bind in Ninject

I have an MVC application using Ninject to connect to a single database. I have been asked to use a Login database to get the connection string for the data. This is so we can authenticate using a LoginDatabase and then go off somewhere else for the client data. This will allow us to have one websit...
pantsmoustache
1

votes
1

answer
35

Views

Ninject.Web.Common.WebHost compatible .net core 2.0

I am trying to use Ninject with a new API project that targets .net Core 2.1 I get this warning when ever I reference the library using nuget 'Package 'Ninject.Web.Common.WebHost 3.3.1' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2....
CodeInColor
1

votes
0

answer
46

Views

How to pass parameters to concrete implementation of IOC Dependency Resolver

I have an MVC 5 web application retrieving employees' attendance records stored in a SQL Server database. I'm also implementing dependency injection through Ninject, and the problem is that I don't know how to tell the concrete implementation of my attendances' class how to filter data by date. At...
Davide Vitali
1

votes
0

answer
33

Views

How to implement parameterized singleton with Ninject

Is there Ninject based way to implement such a factory: public class AspectProviderFactory { private readonly Dictionary Instances = new Dictionary(); public IAspectProvider Get(string aspectName) { if (!Instances.ContainsKey(aspectName)) Instances[aspectName] = new AspectProvider(aspectName); re...
Alexey Khoroshikh
1

votes
0

answer
13

Views

Missing Reference on specific machine using Fody Costura with Topshelf and Ninject

I have built a little Windows service that runs on a client's machine, connects to a local database and posts that data to a webservice. I'm using Topshelf with Ninject, and the code is essentially boilerplate, right from the template. I added Fody Costura to make it simple to deploy, and have suc...
Mark Bennett
1

votes
1

answer
1.7k

Views

ASP.NET, Ninject and MVC: Performance Load problems

problem description: This model works fine with one user at a time. As soon as I get multiple users at once, I get a serious of errors relating to not closing my SqlDataReader. When i turn off lazy loading like this: persistenceModel.Conventions.OneToManyConvention = (prop => prop.SetAttribute('l...
Shane
1

votes
1

answer
991

Views

Ninject 2 configuration sample for class library projects

I'm gonna use Ninject 2.0 in a project and looking for a good sample on how to configure it for a class library case. Many samples are available for WebForms and ASP.NET MVC but in my case I want to inject a Repository in my DataAccess project to Services project (both are class libraries) and I don...
Mahdi Taghizadeh
1

votes
1

answer
1.5k

Views

Using Ninject With Entity Framework

I have a repository Class which takes in a ObjectContext called 'TestDB'. I when I launch my web application i'm getting a 'Unable to load the specified metadate resource', almost like its not picking up the connection settings from my web.config file anymore. Here is a snippet of my code. [Inject]...
OneSmartGuy
1

votes
1

answer
412

Views

Instantiation failure and singleton-behaviour interaction [NInject1]

I have set up a NInject (using version 1.5) binding like this: Bind().ToMethod(ctx => { try { // create session factory, might fail because of database issues like wrong connection string } catch (Exception e) { throw new DatabaseException(e); } }).Using(); As you can see, this binding uses a singl...
Maximilian Csuk
1

votes
1

answer
323

Views

Can Ninject be instructed to apply context-based logic to all bindings?

We've begun using Dependency Injection recently, and we've chosen Ninject 2 (for now) as our IoC Container. As I refactor our solution to incorporate DI principles, I've run into something that bugs me a little, and I'm wondering if there's an easy way to get around it. For our data layer, we have...
StriplingWarrior
1

votes
1

answer
448

Views

how do use Ninject with class libraries I am developing?

If I am working on a class library how do I make use of Ninject here? i.e., from the internal class library point of view and also from the client code? For example: should the class library have its own IOC set up, or should it always assume the client code will supply? if no (ie it's up to the cli...
Greg
1

votes
1

answer
877

Views

How to stub ninject's IKernel using Rhino Mocks?

var mocks = new MockRepository(); var access = new Access(); access.ShowRepository = _mocks.Stub(); access.ShowRepository.Stub(x => x.GetShows()).Return(new List()); var kernel =_mocks.Stub(); kernel.Stub(x => x.Get()).Return(access); This throws an ArgumentNullException: Message: Value cannot be nu...
Dave
1

votes
2

answer
882

Views

How to configure Ninject for ASP.NET MVC using LinqToSQL and Repository Pattern

I have done some searching around but have not been able to figure out how to bind LinqToSql data context's with specified connection strings into different repositories. This binding is performed in global.ajax when routes are registered. I'm using a fairly standard repository pattern to decouple t...
Joshua Hayes
1

votes
3

answer
588

Views

IoC Container Hurdle for ASP.Net MVC Newb

I must admit that I'm new to ASP.Net MVC and I'm currently researching all the best practices on how to start my new project. So far I have understood the concepts of the Repository Pattern and Unit of Work and I have gone onto Dependency Injection and Inversion of Control (IoC). I have been looki...
nfplee
1

votes
1

answer
113

Views

Help with Ninject in asp.net mvc 2

Im trying to add Ninject to my app so that (maybe) I can try creating/running tests in it... so I need a little help setting this up here's my controller public class CompaniesController : Controller { private ICompaniesServices _service; public CompaniesController() { _service = new CompaniesServic...
ignaciofuentes
1

votes
2

answer
206

Views

How to add new object to track in Ninject after Application_Started?

Is it possible to add a new object that Ninject should be responsible for (lifetime, injection etc.) in an ASP.NET application after the Application_Started event is fired? My application needs to dynamically designate objects that should be tracked well after the application is started
Omar
1

votes
1

answer
459

Views

Dependency Inject with Ninject 2.0

A little question regarding Ninject. I use a WCF 'duplex channel' to communicate with a service. The channel is defined as an interface, lets call it IMyChannel for simplicity. To instantiate a channel we use DuplexChannelFactory object's CreateChannel() method. So far I have manage to bind the fac...
Goodiepal
1

votes
1

answer
653

Views

Use factory method in Ninject that I can't add attribute to

I try to use Ninject to inject a XmlReader. The problem is that it is created by a factory method insted of a constructor. And I can't add a [Inject] to code in the .NET Framework. Now I use following binding to create the XmlReader: Bind() .ToMethod( x => XmlReader.Create( (string) GetParameter(x,...
magol
1

votes
1

answer
751

Views

Ninject interception extension with WCF gives me an “Object reference not set to an instance of an object.” error

I'm getting started with the Ninject interception extension and can't get it to work in my WCF service. With the WCF extension, ninject works fine, it's the interception that's giving me trouble. Maybe i'm doing it wrong? When I try to add the LinFuModel in the kernel constructor it tells me it's al...
Syg
1

votes
1

answer
283

Views

Problem with multiple dependency injection using Ninject

As a disclaimer I shall say that I'm still trying to wrap my head around the whole DI pattern therefore I guess it's needless to say that my code might probably have a major conceptual bug. With that, what I'm trying to do is inject two properties on the following implementation: interface ISurface...
Nano Taboada
1

votes
2

answer
572

Views

How to use Ninject with Query Parameters in MVC?

I am following Steven Sanderson's Pro MVC2 book and have a question about using Ninject. In the sports store example, we have in Global.asax.cs ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory()); and NinjectControllerFactory is defined as: public class NinjectControllerFa...
user556373
1

votes
1

answer
2.3k

Views

Help with Ninject in mvc3!

Heres my problem. My app has several projects. WEB (Controllers and views) Services Data (edmx and Repositories) Entities (POCO) Tests So in my Web project I have the ninject configuration [assembly: WebActivator.PreApplicationStartMethod(typeof(PublicPanama.AppStart_NinjectMVC3), 'Start')] namespac...
ignaciofuentes

View additional questions