-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow injecting additional registrations during the creation of service lifetimescope #57
Comments
Hey; we're a big bogged down getting the Autofac v6 release out right now. To be honest, I'm not 100% clear what is being asked here; @alexmg, can you offer any insight? |
Thanks for reporting this issue @n3gwave. I have added a global hook that allows registrations to be added to the lifetime scope created for the service instance. This is provided to the The registration should look something like the example below. The builder.RegisterServiceFabricSupport(
configurationAction: b =>
b.Register(c => FabricTelemetryInitializerExtension.CreateFabricTelemetryInitializer(
c.Resolve<ServiceContext>()))
.As<ITelemetryInitializer>()
.SingleInstance()); I'm not sure if the timing of this will be adequate for the
If there are issues it would be great to have an example application that could be used for testing. I was not able to test this with the Service Fabric demo application because it has not been updated to include .NET Core examples. It would also be good to have the demo application include the configuration of Application Insights telemetry, but I don't have time to get to this now. @alistairjevans @alsami @tillig Please hold off releasing the |
Hey, I think that should be fine at least for things I'm doing. You are right that for case with WebHostBuilder and default template this would still be problem, but I use a combination of generic host with Autofac DI and then for services that needs http I create my own http communication listener (forked from kestrel) but has very important detail: |
Hi @n3gwave. It would be great if you could use the package from MyGet to confirm that this does address your issue. If everything looks good, we can release the package with the changes. |
Problem Statement
Service registration is closed for extension and makes injecting additional dependencies within the SF service lifetime scope impossible. There is a challenge with proper initializing the Application Insights with Autofac. Based on AI for SF docu (https://github.com/microsoft/ApplicationInsights-ServiceFabric) there is a requirement to register FabricTelemetryInitializerExtension.CreateFabricTelemetryInitializer(ServiceContext) as a ITelemetryInitializer. However, this must be done while creating the lifetimescope in RegisterServiceAsync method. Otherwise, we don't have ServiceContext available.
Desired Solution
This can be easily achieved by adding additional parameter of type Action to RegisterStatefulServiceFactory/RegisterStatelessServiceFactory/RegisterActorFactory methods and make sure the parameter is passed from AutofacServiceExtensions class methods. Then in factory methods we can add custom dependencies in Begin scope action
Then we could register service with following code:
Alternatives You've Considered
I haven't found any workaround to initialize the SF telemetry initializer in the scope created for SF service. I cannot do it in the Kestrel Webhost, as I have remoting methods (my service implements the SF's IService interface).
Additional Context
In my solution, I use a mix of HostBulder with Autofac along with Autofac SF integration so
registering FabricTelemetryInitializer out of service scope ends with exception as serviceContext is not resolved during the Build operation on HostBuilder. The reason for that is the AI integration which needs to resolve ILogger thus it pulls for all ITelemetryInitializers as well.
Additional benefit is that we could also register the IReliableStateManager. Now it's not possible because state manager is properly created withing the StatefulService and lifetime scope registration is being done befor. However with some helper class:
we can inject additional registration
and make sure we update reference StateManager in RunAsync as follows:
the last step is required as for some reason new ReliableStateManager(resolve(ctx)) doesn't create valid reliable manager object - at least in my case injected stateful context in ctor is not assigned properly.
The text was updated successfully, but these errors were encountered: