Git Product home page Git Product logo

msfx.di.extensions.samples's Introduction

Msfx.DI.Extensions.Samples

Asp.net MVC 5

Download the binaries from here

Add below entry in the Global.asax.cs

  ControllerBuilder.Current
      .SetControllerFactory(
          new DIControllerFactory(
              new AttributeBasedDIContext(
                  typeof(HomeController) // This should be any controller or class from current assembly
                  , Scanners.DependencyScanTarget.Assembly)
              .Scan()));

Now in your controller, there is no need to inject / and instantiate any dependency

using Msfx.DI.Attributes;
using Msfx.DI.Extensions.Samples.AspMvc5.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Msfx.DI.Extensions.Samples.AspMvc5.Controllers
{
    public class HomeController : Controller
    {
        [AutoInject] // <- Add this attribute and [Injectable] attribute in the HomeService class
        public HomeService homeService; // This service class will be injected automatically
        public ActionResult Index()
        {
            string serviceData = this.homeService.GetData(); // using the service class
            return View();
        }
    }
}

msfx.di.extensions.samples's People

Contributors

adansari avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.