Maybe I'm not using Unity correctly. Advice on removing an instance please?

May 21, 2015 at 10:32 PM
Edited May 21, 2015 at 10:41 PM
First off I have a wpf Modular Composite Application with Prism and Unity. I have two regions a ToolbarRegion and a ContentRegion. My ContentRegion is a tabcontrol. I click on a MenuItem in my ToolbarRegion to add a view in my ContentRegion. That adds the view in a new tab to my ContentRegion from the different modules. The only other way I can think of is using the LifetimeManager in Unity to remove the view from the container. BUT my viewmodel does not see the container. How can I remove the view when I register them like this. My application will require constant opening and closing of views should I look for an IoC that suits my needs better?
     public class ModuleAModule : ModuleBase
    public ModuleAModule(IUnityContainer container, IRegionManager regionManager)
        : base(container, regionManager) { }

    protected override void InitializeModule()
        RegionManager.RegisterViewWithRegion(RegionNames.ToolbarRegion, typeof(ViewAButton));


    protected override void RegisterTypes()

             Container.RegisterType<ICustomersViewModel, CustomersViewModel>();
            Container.RegisterType<IViewAViewModel, ViewAViewModel>();
            Container.RegisterType<IViewAUserViewModel, ViewAUserViewModel>();
            Container.RegisterType<IUserViewModel, UserViewModel>();
public abstract class ModuleBase : IModule
    protected IRegionManager RegionManager { get; private set; }
    protected IUnityContainer Container { get; private set; }

    public ModuleBase(IUnityContainer container, IRegionManager regionManager)
        Container = container;
        RegionManager = regionManager;

    public void Initialize()
Shell Xaml for Region
<TabControl x:Name="tabControl" prism:RegionManager.RegionName="{x:Static inf:RegionNames.ContentRegion}" 

        VerticalAlignment="Stretch" Margin="0.786,7.98,-3.786,3.416" RenderTransformOrigin="0.5,0.5" Grid.Row="1" Grid.RowSpan="3">
            <Style TargetType="{x:Type TabItem}" >
                <Setter Property="Header" Value="{Binding HeaderInfo}"/>



Shell xaml for getting the view
                    <MenuItem Header="Company Name" Command="{x:Static inf:ApplicationCommands.NavigateCommand}" CommandParameter="{x:Type views1:ViewAView}"/>
                    <MenuItem Header="User-Definable Choices" Command="{x:Static inf:ApplicationCommands.NavigateCommand}" CommandParameter="{x:Type views1:ViewAUserView}"/>
                <MenuItem Header="User Roles" Command="{x:Static inf:ApplicationCommands.NavigateCommand}" CommandParameter="{x:Type views1:CustomersView}"/>
                     <MenuItem Header="User Choice" Command="{x:Static inf:ApplicationCommands.NavigateCommand}" CommandParameter="{x:Type views1:UserView}"/>

picture of UI