Skip to content

Beta 5 - Services does not expose IServiceCollection #42

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

Closed
jpiell opened this issue Jan 23, 2020 · 4 comments
Closed

Beta 5 - Services does not expose IServiceCollection #42

jpiell opened this issue Jan 23, 2020 · 4 comments

Comments

@jpiell
Copy link

jpiell commented Jan 23, 2020

While the TestServiceProvider now inherits the IServiceCollection Interface, the IServiceCollection interface is not exposed to the client, leaving the client with no way to register services.

Please expose a property that will return the IServiceCollection.

var modal = new Mock();
Services.AddService(modal.Object); <--- No longer valid.

In addition if you expose IServiceCollection:

services.AddTelerikBlazor(); will be exposed <--- Needed for TelerikGrid

AddScoped
AddSingleton

etc

@egil
Copy link
Member

egil commented Jan 23, 2020

Those Add* methods are part of the Microsoft.Extensions.DependencyInjection namespace. Let me update the release notes to make it clear you need to add that now.

Import that in your .cs or .razor file and you are good to go:

using Microsoft.Extensions.DependencyInjection;

@egil
Copy link
Member

egil commented Jan 23, 2020

Please expose a property that will return the IServiceCollection.

I am not sure why there is a need for an explicit IServiceCollection to be exposed. Due to inheritance, the TestServiceProvider is one, so it should not be needed. See my coding example in the related issue (#38)

@jpiell
Copy link
Author

jpiell commented Jan 23, 2020

I am still getting:

Severity Code Description Project File Line Suppression State
Error CS1061 'TestServiceProvider' does not contain a definition for 'AddService' and no accessible extension method 'AddService'

@egil
Copy link
Member

egil commented Jan 23, 2020

Thats because there is no AddService any more. You need to call AddSingleton now, which is an extension method from Microsoft.Extensions.DependencyInjection.

Before beta-5, TestServiceProvider was not a true IServiceCollection, thus it implemented a bunch of AddServices methods. That is now changed, and we rely on the from extension method from Microsoft.Extensions.DependencyInjection.

I am sorry if that was not clear enough in the release notes

@egil egil closed this as completed Jan 23, 2020
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