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

Service locator is not registering services decorated with attribute "ServiceLocatorRegistration" #1504

Closed
gofrogi opened this issue Dec 16, 2019 · 5 comments
Assignees
Labels
bug
Milestone

Comments

@gofrogi
Copy link

@gofrogi gofrogi commented Dec 16, 2019

since version > 5.9 such kind of registration doesn't work anymore.
[ServiceLocatorRegistration(typeof(IPropertyVersionService), ServiceLocatorRegistrationMode.Transient)] public class PropertyVersionService : IPropertyVersionService { ... }
oddly enough, registration without second parameter works.

Component

ServiceLocator

Version of Library

5.11.2

Version of OS(s) listed above with issue

Windows 10

Steps to Reproduce

  1. Create a interface ITestService
  2. Create a class TestService : ITestService
  3. Decorate the class TestService with Attribute [ServiceLocatorRegistration(typeof(ITestService), ServiceLocatorRegistrationMode.Transient]
  4. anywhere in program.cs insert the code:
ServiceLocator.Default.AutoRegisterTypesViaAttributes = true;
var test = ServiceLocator.Default.ResolveType<ITestService>();
  1. start the program

Expected Behavior

test should contain a object of type TestService

Actual Behavior

UnregisteredServiceException or something alike.

@GeertvanHorrik

This comment has been minimized.

Copy link
Member

@GeertvanHorrik GeertvanHorrik commented Dec 17, 2019

Please provide a failing unit test so we can look into this.

@gouranga

This comment has been minimized.

Copy link

@gouranga gouranga commented Dec 18, 2019

@GeertvanHorrik There you go WpfApp1.zip.
If you change nuget packages to 5.9.0 — everything works:
5 9-works

Also, something is wrong with registering types with conversions and filtering. For example I have a lot of Telerik controls and this line should exclude everything from Telerik.* namespace:

serviceLocator.RegisterTypesUsingAllConventions().ExcludeAllTypesOfNamespace("Telerik");

But it doesn't happening.

@GeertvanHorrik GeertvanHorrik added this to the 5.12.0 milestone Dec 19, 2019
@GeertvanHorrik

This comment has been minimized.

Copy link
Member

@GeertvanHorrik GeertvanHorrik commented Dec 19, 2019

The reason is that the TypeCache is no longer aggressively loaded in advance:

foreach (var type in TypeCache.GetTypes(allowInitialization: false))

The way to solve this with the current stable version is to call TypeCache.InitializeTypes before setting the property to true.

In the near future we will allow type cache initialization for the auto registration manager (makes sense when using the registration via attributes).

GeertvanHorrik added a commit that referenced this issue Dec 19, 2019
…ttribute "ServiceLocatorRegistration"
@GeertvanHorrik

This comment has been minimized.

Copy link
Member

@GeertvanHorrik GeertvanHorrik commented Dec 19, 2019

Fixed in Catel Build - 5.12.0-beta.25

@lock

This comment has been minimized.

Copy link

@lock lock bot commented Dec 23, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Dec 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants
You can’t perform that action at this time.