Dispose for objects created by d:DesignInstance

178 Views Asked by At

Is there any way to dispose of objects that were created by the following markup...

<UserControl x:Class="NodeBrowser"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d" 
         d:DesignHeight="344" d:DesignWidth="589"
         d:DataContext="{d:DesignInstance Type=local:NodeBrowserViewModel, IsDesignTimeCreatable=True}"
         >
    <Whatever...>
</UserControl>

My design instance creates a connection to a database so the first time I design time test this control everything works fine but the second time it throws an exception because the first design time data still has an open connection.

Now I know that this doesn't really make sense but it still brings up the issue that objects created via d:DesignInstance don't seem to ever be disposed even if they implement IDisposable.

Is there any solution to this or we basically forced to provide light weight objects that do not require IDisposable for design data?

1

There are 1 best solutions below

0
On

Instead of accessing real database in design time, you can simulating data in design mode using Microsoft Expression Blend, check out this link.