Masstransit: Autofac's Lifetimescope doesn't know all dependencies in a consumer [netstandard/netcoreapp 2.0]

Created on 29 Aug 2017  路  4Comments  路  Source: MassTransit/MassTransit

Is this a bug report?

Yes, i think so. Currently we are using Masstransit with autofac in production. We wanted to port netcoreapp2.0 and netstandard in our projects. .When i tried to move Masstransit .netstandard version and implemented an aspnetcore project, i encountered this issue.

Can you also reproduce the problem with the lastest version?

Yes. Version is : 4.0.0.1272-develop

Environment

  1. Operating system: Win 10
  2. Visual Studio version: 2017 Enterprise 15.3 latest update
  3. Dotnet version: netcoreapp2.0

Steps to Reproduce

  1. Create aspnet core project use autofac as dependency injection container
  2. Register and Confiure Masstransit RabbitMQ and use LoadFrom(componentContext)
  3. Put a debug in a consumer and look into LifetimeScope.

Expected Behavior

Autofac's lifetimescope should resolve all dependencies that provided in composition root which means on ConfigureServices step.

Actual Behavior

Autofac's Lifetimescope doesn't know all dependencies inside of a consumer. It knows only contructor injected dependencies.

Reproducible Demo

I've implemented a demo about that.

LoadFrom using(framework side, it is an abstraction to use Masstransit): https://github.com/stoveproject/Stove/blob/netstandard2.0/src/Stove.RabbitMQ/StoveRabbitMQRegistrationExtensions.cs#L43

Example: https://github.com/stoveproject/Stove/tree/netstandard2.0/test/Stove.Demo.WebApi.Core

I also digged into Masstransit.Autofac's code. AutofacConsumerFactory seemed to me could be relevant, but i don't know :(

container

Most helpful comment

I found the problem. It was in my Autofac abstraction. Masstransit.Autofac works like a charm! Thx guys.

All 4 comments

This is expected behaviour of AutofacConsumerFactory creates a nested LifetimeScope to only manage consumer dependencies, not sure why your expecting all dependencies in a single lifetime scope.

@gertjvr,

I know, as i mentioned this approach works in 3.5.7, same code is not working in .netstandard :( or i'm missing something.

Also i need to resolve hidden dependencies with ILifetimescope. In this sample _scopeResolver.IsRegistered>() is always false since it is late depency not constructor and registered to root scope in composition root.

I'm also not sure of this issue is related with only Masstransit, could be in Autofac's ServiceProvider, just investigating and wanted to help for understand.

I found the problem. It was in my Autofac abstraction. Masstransit.Autofac works like a charm! Thx guys.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gschuager picture gschuager  路  7Comments

ffMathy picture ffMathy  路  3Comments

slaneyrw picture slaneyrw  路  6Comments

fshchudlo picture fshchudlo  路  4Comments

MiguelCosta picture MiguelCosta  路  5Comments