IsRegistered<T>(string) - what does it do?

Sep 16, 2008 at 8:23 PM
Currently, the highest voted work item is "Add IsRegistered<T>(string) method". The idea apparently being to be able to check if type T is registered in the container. My question is - what does "is registered in the container" actually mean?

Are we just looking for type mappings? What should this return for a concrete type that isn't otherwise registered? What if all that's been registered is a lifetime manager? Or just injection?

Could folks give me some idea of the desired semantics here?



Sep 17, 2008 at 4:29 PM
Although I didn't vote on it (would have had I been reviewing) I can see a practical application when Unity is used for factory classes.   Consider the following where btnClick is handling all routed events from the XAML view (last code snippet); if I were to add an additional button (that handled it's own processing) it would crash my factory.  

Would be nice to be able to do the following prior to attempting to resolve (versus try / catch).

if (!isRegistered<IHelloWorldService>(button.Name))

protected void RegisterViewsAndServices()
        .RegisterType<IHelloWorldService, HelloWorldService1>("btnOne")
        .RegisterType<IHelloWorldService, HelloWorldService2>("btnTwo");

private void btnClick(object sender, System.Windows.RoutedEventArgs e)
   Button button = e.OriginalSource as Button;
   IHelloWorldService service = _container.Resolve<IHelloWorldService>(button.Name);
   lblResults.Text = service.GetMessage();

<UserControl x:Class="HelloWorld.Views.HelloWorldView"
        <TextBlock x:Name="lblResults" HorizontalAlignment="Center">HelloWorld</TextBlock>
        <Button x:Name="btnOne">Load HelloWorld1</Button>
        <Button x:Name="btnTwo">Load HelloWorld2</Button>
        <ContentControl cal:RegionManager.RegionName="{x:Static local:RegionNames.HelloWorld}"/>