question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do I remove a type previously registered with IoC?

See original GitHub issue

Hi,

  • ABP 3.4.0
  • ASP.NET MVC 5
if (!IocManager.Instance.IsRegistered<IOzCpCacheManagerStatusResolver>())
{
    if (ApplicationSettings.CacheManager.Enabled.Value && CacheManagerRuntime.Instance.Enabled)
    {
        IocManager.Instance.Register<IOzCpCacheManagerStatusResolver, OzCpCacheManagerStatusEnabledResolver>(DependencyLifeStyle.Singleton);
    }
    else
    {
        IocManager.Instance.Register<IOzCpCacheManagerStatusResolver, OzCpCacheManagerStatusDisabledResolver>(DependencyLifeStyle.Singleton);
    }
}

How do I reverse IocManager.Instance.Register<>() so that IocManager.Instance.IsRegistered() will return FALSE once more?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
acjhcommented, Mar 15, 2018

“You can force the later-registered component to become the default instance via the method IsDefault.”

IocManager.IocContainer.Register(
    Component.For<IOzCpCacheManagerStatusResolver>()
        .ImplementedBy<OzCpCacheManagerStatusEnabledResolver>()
        .Named(Guid.NewGuid().ToString())
        .IsDefault()
);

Reference: https://github.com/castleproject/Windsor/blob/master/docs/registering-components-one-by-one.md#register-more-components-for-the-same-service

0reactions
malimingcommented, Jun 8, 2020

@alexandis Please create a new issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can I un-register types in Unity IoC?
Removing already registered types from UnityContainer at runtime? 1. Registering Types at Runtime · 6. Using Unity, How do I autoregister a ...
Read more >
How to unregister or replace a registered type
Is it possible to unregister their implementations and swap with ours for specific interfaces? (They of course use Autofac as the IoC container)....
Read more >
Remove unwanted instances from ServiceCollection in ...
This article will go a little further, I will show you how to unregister any type of service. Unregister any type of service....
Read more >
Should the usage of DI/IoC remove all occurrences ...
Should the usage of Dependency Injection and an Inversion of Control container remove all occurrences of the " new " keyword from your...
Read more >
Registering a type as an interface and as self with ASP.NET ...
Registering a type or a type factory “as self”. Back to our extension method! We want to start by removing the previous service...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found