autofac/Autofac.Extensions.DependencyInjection

Make AutofacServiceProviderFactory & AutofacServiceScope class public

maliming opened this issue · 4 comments

Is there a reason not to do this?

internal class AutofacServiceScope : IServiceScope, IAsyncDisposable

internal class AutofacServiceScopeFactory : IServiceScopeFactory

The reason is that the fewer things we expose as public, the more flexibility we have to change things under the covers. As library owners, the question isn't "why shouldn't we do it," but actually "why should we?"

hi @tillig

Thanks for your reply, My situation is when I try to customize IServiceProviderFactory and AutofacRegistration I can't access AutofacServiceScopeFactory. The purpose of customizing is to enable features such as property injection(PropertiesAutowired) for all services.

builder.RegisterType<AutofacServiceScopeFactory>().As<IServiceScopeFactory>();

You set property injection up on the registrations, not on the service provider. That is, it's registration-time, not resolve-time. Forcing every resolve through an InjectProperties() on resolve is a bad idea: you'll both get a horrible perf hit and you'll likely accidentally inject properties that shouldn't be injected.

Perhaps a more detailed explanation of your use case would help. We generally don't want people customizing things like the scope factory or service provider for the same reasons you can't "derive and override" the Autofac container class itself or the ContainerBuilder - folks can get in some rough spots with perf and inadvertent code behavior. If there's a way to help you get what you want without this sort of extension, it'd be better to try for that. But I'm not clear on the actual use case details so I can't offer any help.

Thanks @tillig I will rethink my use case.