ninject

Using ninject with Ninject.Web.Api for Web Api 2 is not working in ASP.NET MVC 5

℡╲_俬逩灬. 提交于 2021-02-18 07:06:20
问题 I am developing an Asp.NET MVC project. My project has web api as well. I am using ASP.NET MVC5 and Web Api 2 with Visual Studio 3. I am doing dependency injection using ninject. I know ninject for web is not working for Web Api 2. So I tried to use Ninject for Web Api. I installed ninject for web api 2 package using nuget package manager Then I installed Ninject.Web using nuget package manager Then in NinjectWebCommon, I added this line in RegisterServices private static void

Accessing the Ninject Kernel Globally

大憨熊 提交于 2021-02-06 08:39:27
问题 This question is not specifically related to Ninject. It's more of a general coding question, but I'm posting it here in case there might be a better way entirely of handling the issue in Ninject, than what I am trying to do. I would like to know whether it is possible to access the Ninject Standard Kernel globally, from its instance in Global.asax. Here is the code: public class MvcApplication : NinjectHttpApplication { protected override void OnApplicationStarted() { base

NInjecting into a asp.net website httphandler

六月ゝ 毕业季﹏ 提交于 2021-01-28 10:10:18
问题 I'm trying to inject a service into a HttpHandler i wrote. But all I'm getting is a Service with a null value. I have created a small example to illustrate my problem using a normal asp.net website. public class MyHandler :IHttpHandler { [Inject] public IHelloService HelloService { get; set; } public void ProcessRequest(HttpContext context) { context.Response.Write(HelloService.Hello()); } public bool IsReusable { get; private set; } } The Service public interface IHelloService { string Hello

Get role list with associated users in ASP.NET Identity

随声附和 提交于 2021-01-28 05:22:40
问题 I have a role. How can I find the list of users which have that role? public ViewResult Index() { return View(roleManager.RoleList.ToList()); } In this method I take the list of roles there have the user's UsersId . Now how to link it with my UserModel to take the UserName ? I am not so good in the LINQ, and can't find a good idea In the result I want to make a table in the view foreach (RoleModel role in Model) { <tr> <td>@role.Id</td> <td>@role.Name</td> <td>@role.Description</td> <td> @if

.Net常用中间件

ⅰ亾dé卋堺 提交于 2020-08-06 13:14:18
什么是中间件 中间件是介于操作系统和应用软件之间,为应用软件提供服务功能的软件,有消息中间件,交易中间件,应用服务器等。由于介于两种软件之间,所以,称为中间件。 简单讲,中间件就是非业务的技术类组件。 使用中间件的好处 具体地说,中间件屏蔽了底层操作系统的复杂性,使程序开发人员面对一个简单而统一的开发环境,减少程序设计的复杂性,将注意力集中在自己的业务上,不必再为程序在不同系统软件上的移植而重复工作,从而大大减少了技术上的负担。 中间件带给应用系统的,不只是开发的简便、开发周期的缩短,也减少了系统的维护、运行和管理的工作量,还减少了计算机总体费用的投入。 .Net常见的中间件 Log4Net、NLog(日志记录) Unity、Ninject(IOC容器) EF框架、NHibernate(ORM框架) Quartz.NET(开源的作业调度框架) Socket(通讯)、Redis(缓存) 来源: oschina 链接: https://my.oschina.net/u/4299292/blog/4474147

浅谈IOC

混江龙づ霸主 提交于 2020-08-04 11:39:24
一、引言 IOC-Invertion of Control,即控制反转,是一种程序设计思想,世上本没有路,走的人多了便有了路,本文将一步步带你了解IOC设计思想的演进之路。 在学习IOC之前我们先初步了解几个概念 依赖(Dependency) :就是有联系,表示一个类依赖于另一个类 依赖倒置原则(DIP) :设计模式六大原则之一,是一种软件架构设计原则 控制反转(IOC) :一种软件设计原则,上层对下层的依赖(即底层模块的获得)交给第三方 依赖注入(DI) :实现IOC的一种方式、手段 IOC容器 :依赖注入的框架,用来映射依赖,管理对象创建和生存周期 二、依赖 依赖就是有联系,有地方使用它就是有依赖它,下面看一个简单的示例 class BMW { public string Show() { return " 宝马 " ; } } class ChinesePeople { private BMW bmw = new BMW(); public void Run() { Console.WriteLine($ " 今天开{bmw.Show()}上班 " ); } } class Program { static void Main( string [] args) { ChinesePeople people = new ChinesePeople(); BMW bmw =

Can't get Ninject.Extensions.Interception working

淺唱寂寞╮ 提交于 2020-08-02 05:53:48
问题 I've been trying for ages to figure this our. when i try to bind my class with an interceptor i'm getting the following exception on the line Kernel.Bind<MyClass>().ToSelf().Intercept().With<ILoggerAspect>(); Error loading Ninject component IAdviceFactory. No such component has been registered in the kernel's component container I've tried with and without LoadExtensions, With about with using a Module to set up my bindings and my last attempt looks like this internal class AppConfiguration {

Ninject with Web Api, SignalR, MVC and OWIN

拟墨画扇 提交于 2020-06-27 11:28:29
问题 I am using a Ninject DI in my web application with a bunch of technoligies from Asp.Net stack (MVC, Web Api 2, SignalR). I have managed to make DI work for all technologies in use with the following approach: public static class NinjectWebCommon { private static readonly Bootstrapper bootstrapper = new Bootstrapper(); /// <summary> /// Starts the application /// </summary> public static void Start() { DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule)); DynamicModuleUtility

Dependency injection (ninject) using strings, anti-pattern?

柔情痞子 提交于 2020-06-13 19:05:13
问题 I have some code that is using ninject to inject dependencies, these dependencies are actual strings. Is this an anti-pattern to inject strings rather than creating a new object for example. I.e. I wanted to inject Username and Password, would it actually be better to create a small class called credentials with 2 properies of Usernamd and Password and inject this ? Injecting strings into constructors can be done via kernel.Bind<IUser>().To<User>() .WithConstructorArgument(@"username",