ninject

Issue using ASP.Net MVC 4 Web API with Ninject.Web.WebApi

拈花ヽ惹草 提交于 2019-11-30 01:36:19
I'm trying to use the new ASP.Net MVC 4 Web API project template with Ninject but have hit a wall on the following error: Method 'GetFilters' in type 'Ninject.Web.WebApi.Filter.DefaultFilterProvider' from assembly 'Ninject.Web.WebApi, Version=3.0.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7' does not have an implementation. I am creating a brand new project in Visual Studio 2010 using the ASP.Net MVC 4 -> Web API template and I am using the latest Ninject NuGet packages: Ninject 3.0.1.10 Ninject.Web.Common 3.0.0.7 Ninject.Web.WebApi 3.0.0.2 I have attempted the solution presented in

How to intercept all the ASP.NET WebApi controller action methods calls with Ninject interception for logging?

匆匆过客 提交于 2019-11-29 23:36:00
Our company has the need to log certain things each time one of our action methods of our ASP.NET WebApi controllers gets called. Since we use Ninject for the DI right now, we'd like to use it also for this purpose. This is what I have tried so far. I have Ninject, Ninject.Extensions.Interception and Ninject.Extensions.Interception.DynamicProxy installed through NuGet and I have the following module public class InterceptAllModule : InterceptionModule { public override void Load() { Kernel.Intercept(p => p.Request.Service.Name.EndsWith("Controller")).With(new TimingInterceptor()); } } Where

MVC 3 - how to implement a service layer, do I need repositories?

萝らか妹 提交于 2019-11-29 21:34:29
I am currently building my first MVC 3 application, using EF Code First, SQL CE and Ninject. I have read a lot about using Repositories, Unit of Work and Service Layers. I think I have got the basics sorted out, and I have made my own implementation. This is my current setup: Entities public class Entity { public DateTime CreatedDate { get; set; } public Entity() { CreatedDate = DateTime.Now; } } public class Profile : Entity { [Key] public Guid UserId { get; set; } public string ProfileName { get; set; } public virtual ICollection<Photo> Photos { get; set; } public Profile() { Photos = new

Using Ninject to fill Log4Net Dependency

风格不统一 提交于 2019-11-29 21:28:47
I use Ninject as a DI Container in my application. In order to loosely couple to my logging library, I use an interface like this: public interface ILogger { void Debug(string message); void Debug(string message, Exception exception); void Debug(Exception exception); void Info(string message); ...you get the idea And my implementation looks like this public class Log4NetLogger : ILogger { private ILog _log; public Log4NetLogger(ILog log) { _log = log; } public void Debug(string message) { _log.Debug(message); } ... etc etc A sample class with a logging dependency public partial class

Ninject with MembershipProvider | RoleProvider

本小妞迷上赌 提交于 2019-11-29 20:57:41
问题 I'm using ninject as my IoC and I wrote a role provider as follows: public class BasicRoleProvider : RoleProvider { private IAuthenticationService authenticationService; public BasicRoleProvider(IAuthenticationService authenticationService) { if (authenticationService == null) throw new ArgumentNullException("authenticationService"); this.authenticationService = authenticationService; } /* Other methods here */ } I read that Provider classes get instantiated before ninject gets to inject the

Ninject: How do I inject into a class library?

三世轮回 提交于 2019-11-29 20:12:46
问题 To start I'm using Ninject 1.5. I have two projects: Web project and a Class library. My DI configuration is within the Web project. Within my class library I have the following defined: public interface ICacheService<T> { string Identifier { get; } T Get(); void Set( T objectToCache, TimeSpan timeSpan ); bool Exists(); } And then a concrete class called CategoryCacheService . In my web project I bind the two: Bind( typeof( ICacheService<List<Category>> ) ).To( typeof(CategoryCacheService))

HttpContext.Current null inside async task

最后都变了- 提交于 2019-11-29 17:55:31
问题 I have a method that uses a repository ( userRepo ): public override Task<IdentityResult> CreateLocalUserAsync(IUser user, string password, CancellationToken cancellationToken) { var task = new Task<IdentityResult>(() => { TUserEntity newUser = new TUserEntity { Id = user.Id, UserName = user.UserName, Password = password }; userRepo.Save(newUser).Flush(); return new IdentityResult(true); }, cancellationToken); task.Start(); return task; } The userRepo object has a dependency that uses

Ninject factory create T based on enum

China☆狼群 提交于 2019-11-29 16:25:33
I want to let Ninject resolve an instance of T based on a specific enum input value. I have read about Ninject's factory extension, but I couldn't find any example having the factory resolve a specific class based on an enum. Each class derives from a base class and that derived class has several, different interfaces that Ninject also has to resolve. For example this is how the interface should look like: public interface IProcessFactory { T Create<T>(ProcessIndex processIndex) where T : BaseProcess; } How can this be achieved ? This is not supported out of the box. You can customize it by

Which is a good approach to test Ninject bindings?

青春壹個敷衍的年華 提交于 2019-11-29 16:21:34
问题 We use ninject in all our projects, and as you will know, sometimes it becomes hard to test if the kernel would be able to resolve every type at execution time, because sometimes control gets lost when the magnitude of bindings and autobindings (through ninject extensions) is high. So, what I'm asking here is how can I know that my kernel, after loading all modules and bindings, will be able to resolve every type ? Do you do any kind of Unit Test? Or you just make acceptation tests of the

Using Ninject (or some other container) How can I find out the type that is requesting the service?

孤街醉人 提交于 2019-11-29 15:39:46
问题 Suppose I have an interface for a service: public interface IFooService { void DoSomething(); } And a concrete implementation of that service that is a generic: public class FooService<TRequestingClass> : IFooService { public virtual void DoSomething() { } } And I have some other class that needs an instance of IFooService: public class Bar { private IFooService _fooService; public Bar(IFooService fooService) { this._fooService = fooService; } } I need to wire up my IoC container such that