{
  "$type": "site.standard.document",
  "canonicalUrl": "https://johnnyreilly.com/posts/autofac-6-integration-tests-and-generic-hosting",
  "description": "Integration tests using Autofac have been affected by a long-standing issue in .NET Core 3.0. Alternative approaches may not last long.",
  "path": "/posts/autofac-6-integration-tests-and-generic-hosting",
  "publishedAt": "2020-10-02T00:00:00.000Z",
  "site": "at://did:plc:yy3apqjlms24kso7ahn7lbmb/site.standard.publication/3mova7c4nho2b",
  "tags": [
    "asp.net",
    "automated testing"
  ],
  "textContent": "I blogged a little while ago around to support integration tests using Autofac. This was specific to Autofac but documented a workaround for a long standing issue with ConfigureTestContainer that was introduced into .NET core 3.0 which affects all third-party containers that use ConfigureTestContainer in their tests.\n\n\n\nI'll not repeat the contents of the previous post - it all still stands. However, with Autofac 6 the approach documented there will cease to work. This is because the previous approach relied upon ContainerBuilder not being sealed. As of Autofac 6 it is.\n\nHappily the tremendous Alistair Evans came up with an alternative approach which is listed below:\n\nUsing this in place of the previous approach should allow you continue running your integration tests with Autofac 6. Thanks Alistair!\n\nConcern for third-party containers\n\nWhilst this gets us back up and running, Alistair pointed out that this approach depends upon a deprecated interface. This is the IStartupConfigureContainerFilter which has been marked as Obsolete since mid 2019. What this means is, at some point, this approach will stop working.\n\nThe marvellous David Fowler has said that ConfigureTestContainer issue should be resolved in .NET. However it's worth noting that this has been an issue since .NET Core 3 shipped and unfortunately the wonderful Chris Ross has advised that it's not likely to be fixed for .NET 5.\n\nI'm very keen this does get resolved in .NET. Building tests upon an Obsolete attribute doesn't fill me with confidence. I'm a long time user of Autofac and I'd like to continue to be. Here's hoping that's made possible by a fix landing in .NET. If this is something you care about, it may be worth upvoting / commenting on the issue in GitHub so the team are aware of desire around this being resolved.",
  "title": "Autofac 6, integration tests and .NET generic hosting"
}