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

fix: Add HasRegistered check in InitializeReactiveUI for DI Containers. #2539

Conversation

HrlecMatej
Copy link
Contributor

@HrlecMatej HrlecMatej commented Sep 23, 2020

What kind of change does this PR introduce?

Fixes #2537
Allow registering custom services before calling InitializeReactiveUI by adding HasRegistration check.

This is mostly to allow cleaner substitution of custom services when using dependency inversion. You wouldn't need to unregister or have a redundant service registration anymore.

What is the current behavior?

Registers a service, without checking if a registration already exists.

What is the new behavior?

Now it checks, if a service with a certain type is already registered.

With this approach, one would register a custom service before the initialization call (like you currently do to override e.g. ILogger in InitializeSplat). Autofac DI is used in the example:

// Register your overrides first
builder.RegisterInstance(new NullLogger()).As<ILogger>();
builder.RegisterType<MyCustomViewLocator>().As<IViewLocator>().SingleInstance();
// etc.

// Since I am using AutofacDependencyResolver, I create it at this point
var autofacResolver = builder.UseAutofacDependencyResolver();
// Register the resolver in Autofac so it can be later resolved
builder.RegisterInstance(autofacResolver);

// Then call InitializeReactiveUI, which would ignore already registered IViewLocator
autofacResolver.InitializeReactiveUI();

This means there aren't any redundant registrations, and no potential unexpected side-effects from that.

What might this PR break?
Nothing should brake.

Please check if the PR fulfills these requirements

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

Other information:

@HrlecMatej HrlecMatej requested a review from a team September 23, 2020 07:49
@glennawatson
Copy link
Contributor

This class is changing soon so will likely have to integrate the changes elsewhere. @RLittlesII mind looking at the changes and integrating into your work.

@glennawatson glennawatson changed the title PR: Allow registering custom services before calling InitializeReactiveUI by adding HasRegistration check #2537 fix: Add HasRegistered check in InitializeReactiveUI for DI Containers. Sep 23, 2020
@glennawatson
Copy link
Contributor

This causes issues with some DI engines so will revisit later.

@github-actions
Copy link

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

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow registering custom services before calling InitializeReactiveUI by adding HasRegistration check
2 participants