On Sat, Dec 17, 2016 at 12:23 PM, Travis Illig <
travis...@gmail.com> wrote:
> Be careful of that version of the controller activator. It's not taking into
> account request-based lifetime scopes, so you're going to get every
> controller out of the root lifetime scope. I will assume that what you've
> posted is a simplified version of whatever it is you're actually doing.
Yes, it's a draft first version. Thanks for the clarification and for
the insights.
> You can always try registering things as a lambda.
>
> builder.Register(ctx => new
> AutofacHttpControllerActivator(ctx.Resolve<ILifetimeScope>())).As<IHttpControllerActivator>().SingleInstance();
>
> By using SingleInstance there, the lifetime scope that gets resolved will be
> the root scope - the container.
>
> However, in Web API 2 (e.g., not .NET Core) things aren't very consistent.
> Some things get cached that shouldn't (like filter instances). There's a
> whole "dual container" sort of thing where you have the dependency resolver
> but also a services container on the HttpConfiguration... I would recommend
> not trying to force a square peg into a round hole. If you don't have to
> make the code complex just "for consistency" then, seriously, don't. Just
> build the activator and set it on the Services collection and call it a day.
> It doesn't really matter when that happens as long as it's before the app
> starts taking requests.
As I've learned/am learning, yes.
> All of this mess got fixed in
ASP.NET Core because it was such a mess.
You bet, I appreciate that and am awaiting the vNext to supersede
API/MVC, if I understand the promised life cycle correctly. It's
certainly taken them long enough to work through the thing.
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Autofac" group.
> To unsubscribe from this topic, visit
>
https://groups.google.com/d/topic/autofac/AwDtuJhAXZU/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
>
autofac+u...@googlegroups.com.
> To post to this group, send email to
aut...@googlegroups.com.
> Visit this group at
https://groups.google.com/group/autofac.
> For more options, visit
https://groups.google.com/d/optout.