Autofac.EasyPropInject 1.2.5

.NET Standard 2.0
dotnet add package Autofac.EasyPropInject --version 1.2.5
NuGet\Install-Package Autofac.EasyPropInject -Version 1.2.5
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Autofac.EasyPropInject" Version="1.2.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Autofac.EasyPropInject --version 1.2.5
#r "nuget: Autofac.EasyPropInject, 1.2.5"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Autofac.EasyPropInject as a Cake Addin
#addin nuget:?package=Autofac.EasyPropInject&version=1.2.5

// Install Autofac.EasyPropInject as a Cake Tool
#tool nuget:?package=Autofac.EasyPropInject&version=1.2.5

Nuget Paypal Donate Github

Important!

Due to breaking changes to Autofac API with version 6.x older Autofac.EasyPropInject Readme can be found in 1.0.x (Autofac ⇐4>) and 1.1.x (Autofac >=5 < 6>). master and 1.2.x will show code examples and info only for Autofac >= 6.

Autofac.EasyPropInject

An extension i created to make it possible to to inject properties by attribute, without any other helper libs in .NET Core for Autofac.

Install

Nuget

Install-Package Autofac.EasyPropInject

DotNetCli

dotnet add package Autofac.EasyPropInject

Contribute / Donations

If you got any Ideas to improve my projects feel free to send an pull request.

If you like my work and want to support me (or want to buy me a coffee/beer) paypal donation are more than appreciated.

Paypal Donate

Usage

Startup.cs

Go to "ConfigureServices" Make sure that you create the Autofac Container as usual for your Framework (Supported is .NET Standard 2+) like its described here: https://autofac.readthedocs.io/en/latest/integration/index.html

and then you create the instance BEFORE any registration.

   public IServiceProvider ConfigureServices(IServiceCollection services)
   {
          ......
          var builder = new ContainerBuilder().AddEasyPropInject();
          
          //Add your services now as usual 
    }
    

Usage in the Code

using Autofac.EasyPropInject.Annotations;
public class MyClass:IMyInterface 
{ 
    public MyClass(ISomeOtherInterface someService) 
    { 
      
    }
    
    [FromAutofac]
    public IUnitOfWork unit { get;set; }


    [FromAutofac] //Since Autofac.EasyPropInject@1.2.5: Support for protected properties
    protected IMyService serviceProtected {get;set;}

    [FromAutofac] //Since Autofac.EasyPropInject@1.2.5: Support for private properties
    private IMyService2 servicePrivate {get;set;}

    [FromAutofac(typeof(IUnitOfWork))]
    public UnitOfWorkBaseClass unit2 {get;set;}
}

Once IMyInterface is resolved and activated EasyPropInject Middleware will try to resolve the types of unit and unit2. In this case EasyPropInject will try to resolve IUnitOfWork from current container and will try to set and Instance of IUnitOfWork to unit2 and use it as UnitOfWorkBaseClass. Warning Since the type casting feature new in 1.2.x of EasyPropInject is handy sometimes its truly unsafe and you should to be sure what you are doing.

Whats new?

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48 net481
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.5 1,736 11/26/2021
1.2.4 1,635 11/26/2021
1.2.3 1,605 11/26/2021
1.2.2 405 10/18/2020
1.2.1 324 10/15/2020
1.2.0 331 10/15/2020
1.1.1 326 10/15/2020
1.1.0 318 10/15/2020
1.0.4 314 10/15/2020
1.0.1 321 10/15/2020
1.0.0 694 9/30/2018

Upgraded to Autofac 6.3.x
Added support for private and protected properties