Skip to content
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

Inability to Retrieve Service Profiles in SceneServiceProvider #112

Open
lynconEBB opened this issue Nov 7, 2024 · 2 comments
Open

Inability to Retrieve Service Profiles in SceneServiceProvider #112

lynconEBB opened this issue Nov 7, 2024 · 2 comments

Comments

@lynconEBB
Copy link

When setting up a service using SceneServiceProvider, it seems the service profile configurations are not accessible from the main ServiceProvider. As a result, the TryGetServiceProfile function cannot retrieve the profile for the service, which impacts functionality.

The current implementation of TryGetServiceProfile appears to restrict configuration lookup to only Providers of type ServiceProviderProfile in the rootProfile parameter.

  public bool TryGetServiceProfile<TService, TProfile>(out TProfile profile,
  ServiceProvidersProfile rootProfile = null) // rootProfile should be of type BaseServiceProfile<IService>
            where TService : IService
            where TProfile : BaseProfile
        {
            if (rootProfile.IsNull())
            {
                rootProfile = ActiveProfile;
            }

            if (!rootProfile.IsNull())
            {
                foreach (var configuration in rootProfile.ServiceConfigurations)
                {
                    if (typeof(TService).IsAssignableFrom(configuration.InstancedType))
                    {
                        profile = (TProfile)configuration.Profile;
                        return profile != null;
                    }
                }
            }

            profile = null;
            return false;
        }

Changing the rootProfile parameter to BaseServiceProfile<IService> would enable SceneServiceProviderProfile to be passed in. This change should make the configurations accessible and allow TryGetServiceProfile to locate the correct profile, as SceneServiceProviderProfile would contain the necessary configurations.

@SimonDarksideJ
Copy link
Contributor

Thanks for the report @lynconEBB , are you planning a PR, if not I will see about updating the implementation.

Also, could you describe a use case in which this would be used, so I can ensure we have test coverage for this pattern?

@lynconEBB
Copy link
Author

Hi @SimonDarksideJ, thank you for the quick response!

I’ve created a pull request to address this issue, which updates the rootProfile parameter type as previously discussed. This adjustment is aimed at providing greater flexibility in accessing service profiles.

For testing, I believe we can cover the essential use cases by calling TryGetServiceProfile with rootProfile instances of both SceneServiceProvidersProfile and ServiceProvidersProfile. Each test should validate that both types can access configurations and retrieve the appropriate profiles for the specified service.

You can review the pull request here: #113.

Thanks for your feedback on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants