Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

ServiceProviderExtensions architecture #539

Open
@grokys

Description

@grokys

I've been trying to understand our service provider architecture and I've got some questions/suggestions regarding ServiceProviderExtensions.

Spot the difference

  • What is the difference between GetService and TryGetService in ServiceProviderExtensions? Documentation says that TryGetService is a "Safe variant of GetService that doesn't throw exceptions if the service is not found." except AFAICS GetService just calls TryGetService, casts the result and doesn't throw anyway.
  • What is the difference between TryGetService and GetExportedValue in ServiceProviderExtensions? They appear to be the same, even though they don't call each other (the code appears to be simply copy/pasted and modified slightly).

Trying to be too clever?

I think understand what the GetService, TryGetService etc methods on ServiceProviderExtensions are trying to do: if the service provider is an IUIProvider, then call GetService on it, otherwise get an instance of IUIProvider from the service provider and call GetService on that. However I wonder if this is more confusing than helpful:

  • If you call provider.GetService(type(T)) then this mechanism will be bypassed, meaning that provider.GetService(type(T)) will give different results to provider.GetService<T>()
  • It masks the fact that there are different service providers for different types of resources.

IMO it would be clearer to see e.g.:

var uiProvider = serviceProvider.GetService<IUIProvider>();
uiProvider.GetSerivce<IConnectionManager>();

Even if this is longer, it gives me some important information: it that tells me that serviceProvider at that point isn't an IUIProvider and that an IUIProvider is needed to get an IConnectionManager.

Wrong Place

The AddCommandHandler methods don't look like they should be in ServiceProviderExtensions to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions