All Projects → AxaGuilDEv → extensions-dependency-injection

AxaGuilDEv / extensions-dependency-injection

Licence: MIT license
Microsoft Extensions DependencyInjection for WCF, and asp.net classic projects

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to extensions-dependency-injection

DotNetDynamicInjector
💉 Dynamically reference external dlls without the need to add them to the project. Leave your project with low dependency and allowing specific dlls according to your business rule or database parameters.
Stars: ✭ 18 (+0%)
Mutual labels:  microsoft, dependency-injection
AzureFunctions.Extensions
This provides some useful extensions for Azure Functions.
Stars: ✭ 81 (+350%)
Mutual labels:  extensions, dependency-injection
android-clean-architecture
🚀🚀🚀 The boilerplate for Android using Kotlin & Clean architecture.
Stars: ✭ 21 (+16.67%)
Mutual labels:  dependency-injection
lamp-luwak
Service-oriented state management for React
Stars: ✭ 12 (-33.33%)
Mutual labels:  dependency-injection
spring-examples
Starter projects with Spring using Java and Kotlin. Contains modules that covers Security with JWT, Spring with Kotlin, Dependency injection simplified etc.
Stars: ✭ 33 (+83.33%)
Mutual labels:  dependency-injection
static-injector
静态依赖注入在Typescript中使用
Stars: ✭ 22 (+22.22%)
Mutual labels:  dependency-injection
BCVAX-Android
No description or website provided.
Stars: ✭ 19 (+5.56%)
Mutual labels:  dependency-injection
WinActive
WinActive is a simple KMS Activator for Microsoft Windows/Office/VisualStudio VL Products!
Stars: ✭ 38 (+111.11%)
Mutual labels:  microsoft
react-native-msal
MSAL for React Native
Stars: ✭ 62 (+244.44%)
Mutual labels:  microsoft
powerapps-packagedeployer-template
Enhanced deployment capabilities when deploying with the Power Apps Package Deployer.
Stars: ✭ 18 (+0%)
Mutual labels:  microsoft
BingMapsSDSToolkit
This toolkit makes it easy to use the Bing Maps Spatial Data Services (SDS) in .NET
Stars: ✭ 39 (+116.67%)
Mutual labels:  microsoft
Microsoft365
Manage Microsoft 365 with PowerShell
Stars: ✭ 30 (+66.67%)
Mutual labels:  microsoft
extensions-rig
A full development environment to build Twitch Extensions. Currently only supports panel extensions but video overlay coming soon.
Stars: ✭ 26 (+44.44%)
Mutual labels:  extensions
libemf2svg
Microsoft (MS) EMF to SVG conversion library
Stars: ✭ 75 (+316.67%)
Mutual labels:  microsoft
NanoSoft
A forum system built using plain php dedicated for C#.NET Developers
Stars: ✭ 20 (+11.11%)
Mutual labels:  microsoft
powerquery-parser
A parser for the Power Query / M formula language, written in TypeScript
Stars: ✭ 79 (+338.89%)
Mutual labels:  microsoft
jimple
Just a dependency injection container to NodeJS and to the browser using new ES6 features
Stars: ✭ 72 (+300%)
Mutual labels:  dependency-injection
extensions
👅 Parse Haskell Language Extensions
Stars: ✭ 45 (+150%)
Mutual labels:  extensions
ferrisetw
Basically a KrabsETW rip-off written in Rust
Stars: ✭ 22 (+22.22%)
Mutual labels:  microsoft
okito
Your best flutter coding friend. All in one; state management, navigation management(with dynamic routing), local storage, localization, dependency injection, cool extensions with best usages and with the support of best utilities!
Stars: ✭ 37 (+105.56%)
Mutual labels:  dependency-injection

AxaFrance Dependency Injection

About

This package allows projects running on older version of .NET Framework to use the new dependency injection framework introduced with ASP.NET Core. It works with OWIN, MVC and WebApi web applications as well as WCF services.

This gives an easier migration path to those projects towards ASP.NET Core by allowing you to write your Injection configuration as if you were on ASP.NET Core.

Packages

Install-Package AxaFrance.Extensions.DependencyInjection.Mvc
Install-Package AxaFrance.Extensions.DependencyInjection.Owin
Install-Package AxaFrance.Extensions.DependencyInjection.WCF
Install-Package AxaFrance.Extensions.DependencyInjection.WebApi

Getting Started

Registering services

You can register your services like you would in ASP.NET Core:

services.AddScoped<IScopedService, ScopedService>()
        .AddTransient<ITransientService, TransientService>()
        .AddSingleton<ISingletonService, SingletonService>();

Using services

Your services registered can now be passed to constructors:

public HomeController(ISingletonService singletonService, IServiceProvider serviceProvider)
{
    this.singletonService = singletonService;
    this.serviceProvider = serviceProvider;
    this.transientServices = Enumerable.Range(0, 10)
                                        .Select(_ => this.serviceProvider.GetService<ITransientService>());
}

The IServiceProvider interface can be used to programmatically get service at runtime.

In WebApi/Mvc you can even use the [FromService] attribute in controller actions:

public ActionResult Index([FromServices] IScopedService scopedService)
{
    //Logic
}

WCF

  1. Install the WCF package:
Install-Package AxaFrance.Extensions.DependencyInjection.WCF
  1. Create a class that inherits DIServiceHostFactory to register your services:
public class WithDependencyInjectionServiceFactory : DIServiceHostFactory
{
    protected override void ConfigureServices(IServiceCollection services)
    {
        services.AddScoped<IDataProvider, SampleDataProvider>();
        services.AddTransient<ISampleService, SampleService>();
    }
}
  1. Declare this class as the factory in the .svc of your webservice:
<%@ ServiceHost Language="C#" Debug="true" Service="AxaFrance.Extensions.DependencyInjection.WCF.Sample.SampleService" Factory="AxaFrance.Extensions.DependencyInjection.WCF.Sample.WithDependencyInjectionServiceFactory" %>

A sample app is available.

OWIN

In an OWIN application, you must register a startup class using the [OwinStartup] attribute:

[assembly: OwinStartup(typeof(Owin.Sample.Startup))]

namespace Owin.Sample
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            ServiceCollection services = new ServiceCollection();
            services.AddScoped<IScopedService, ScopedService>()
                    .AddTransient<ITransientService, TransientService>()
                    .AddSingleton<ISingletonService, SingletonService>();
            
            // Register the service provider
            app.UseScopedServiceProvider(services.BuildServiceProvider());

            //...
        }
    }
}

A sample is also available.

WebApi & MVC

Install the WebApi package:

Install-Package AxaFrance.Extensions.DependencyInjection.WebApi
Install-Package AxaFrance.Extensions.DependencyInjection.Mvc

Register your service collection in Global.asax.cs:

IServiceProvider provider = new ServiceCollection()
    .AddScoped<IScopedService, ScopedService>()
    .AddSingleton<ISingletonService, SingletonService>()
    .AddTransient<ITransientService, TransientService>()
    .AddWebApi()
    .AddMvc()
    .BuildServiceProvider();
System.Web.Mvc.DependencyResolver.SetResolver(new Mvc.DefaultDependencyResolver(provider));

GlobalConfiguration.Configure(config => {
    // ...
    config.DependencyResolver = new DefaultDependencyResolver(provider);
    // ...
});

You need to configure the resolver for both MVC and WebApi if you use both in your application

A sample is also available.

Dependencies

For all packages

  • Microsoft.Extensions.DependencyInjection.Abstractions

For MVC

  • Microsoft.AspNet.Mvc

For Owin

  • Microsoft.Owin
  • Owin

For WCF

  • System.ServiceModel.Primitives
  • Microsoft.Extensions.DependencyInjection

For WebApi

  • Microsoft.AspNet.WebApi

Contributing

We welcome all contributions. Our contribution guidelines can be found here.

Acknowledgement

Thanks to our amazing contributors:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].