Giter Site home page Giter Site logo

dependencyinjection's Introduction

Dependency Injection Extras

Build status Build status

Adds a few extra pieces of the dependency injection system built into AspNet 5.

[ServiceDescriptor] Attribute

Adds an attribute to the Microsoft.Framework.DependencyInjection namespace, that allows you register a specific class with the DI system.

Used by itself the attribute will register all the classes (and base class) with the implementation. You can specific a service type, to indicate a specific interface. You can also indicate the lifetime as supported by AspNet 5.

IServiceCollection.AddAssembly(....)

Extension Method. Scans the given assembly, for the ServiceDescriptor attribute, and adds them to the Service Collection.

ServiceDescriptor.FromAssembly(....)

Extension Method. Scans the given assembly and generates descriptions for each one that was found.

Future Plans

With the new meta programming model being introduced in AspNet 5, there are plans (and samples) that use Roslyn to replace the IServiceCollection.AddAssembly() or `` calls with the appropriate services as defined in the assembly at runtime.

dependencyinjection's People

Contributors

david-driscoll avatar

Stargazers

Valentin Zwick avatar Matthew Abbott avatar

Watchers

James Cloos avatar  avatar Rodney Littles II avatar

Forkers

aspnetsample

dependencyinjection's Issues

Auto-wire services?

Hi,

Just discovered this whilst looking more at ICompileModule, seems you're ahead of me on an idea I've been pondering about auto-wiring services (ala MEF) for ASP.NET 5.

Generally, my idea is along the lines of:

[Transient]
public class Service : IService { }

And have an ICompileModule generate a class through precompilation, such like:

public static class AutoWireServicesExtensions
{
    public static void AutoWire(this IServicesCollection services)
    {
        services.AddTransient<IService, Service>();
    }
}

Which is then added to the compilation, perhaps then modifying the Startup class:

ConfigureServices(IServiceCollection services) 
{
    services.AutoWire();
}

I get the feeling you're actually further along with I am with this train of thought, so its interesting to know where you are at so far?

I think this sort of model could probably be extended to automatically wireup the pipeline middleware too,

[Middleware("MyMiddleware")]
public class MyMiddleware: IMiddleware
{
    public void RegisterMiddleware(IApplicationBuilder app)
    {
        app.UseMiddleware<...>();
    }
}

What I am looking to achieve, is pluggable modules using the ASP.NET 5 runtime model, and how we can create dynamic runtime pipelines, and automatic dependency wireup, without the developer having to do a whole load of bootstrapping work anytime they want to add a new module in.

It works ok for simple 1-project websites, but needs more consideration for more complex CMS-type projects.

What is your current thoughts on this, if you have any?

Wrong

sorry i post at the wrong repo

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.