A day with .Net

My day to day experince in .net

Posts Tagged ‘bot ninject’

Dependency Injection in Microsoft Bot Framework

Posted by vivekcek on January 15, 2017

In this post i will show you, how you can implement dependency injection in Microsoft Bot application.
Basically Microsoft bot application is a Web API service. So you can implement dependency injection, the same way you done it in Web API.

Here i am using Ninject to implement dependency injection.

1. Add below Nuget Packages





2. Go to App_Start folder and open NinjectWebCommon.cs

3. Update the CreateKernel() method by adding below line.

GlobalConfiguration.Configuration.DependencyResolver = new NinjectDependencyResolver(kernel);
return kernel;

4. You may need to add below namespaces in NinjectWebCommon.cs

using System.Web.Http;
using Ninject.Web.WebApi;

5. Register your services in NinjectWebCommon.cs

private static void RegisterServices(IKernel kernel)

6. Use this class inside your MessageController.

public class MessagesController : ApiController
private readonly IMyInterface instance;
public MessagesController(IMyInterface _instance)
  instance = _instance;

Posted in Bot Framework | Tagged: , , | Leave a Comment »