@ -8,7 +8,6 @@
using System ;
using System ;
using System.Reflection ;
using System.Reflection ;
using System.Collections ;
using System.Collections ;
using System.Collections.Specialized ;
using System.Drawing ;
using System.Drawing ;
using System.ComponentModel ;
using System.ComponentModel ;
using System.ComponentModel.Design ;
using System.ComponentModel.Design ;
@ -20,7 +19,8 @@ namespace ICSharpCode.FormsDesigner.Services
public class DefaultServiceContainer : IServiceContainer , IDisposable
public class DefaultServiceContainer : IServiceContainer , IDisposable
{
{
IServiceContainer serviceContainer ;
IServiceContainer serviceContainer ;
ArrayList services = new ArrayList ( ) ;
Hashtable services = new Hashtable ( ) ;
bool inDispose = false ;
public DefaultServiceContainer ( )
public DefaultServiceContainer ( )
{
{
@ -35,12 +35,13 @@ namespace ICSharpCode.FormsDesigner.Services
#region System.IDisposable interface implementation
#region System.IDisposable interface implementation
public virtual void Dispose ( )
public virtual void Dispose ( )
{
{
foreach ( object o in services ) {
inDispose = true ;
if ( o = = this ) {
foreach ( DictionaryEntry o in services ) {
if ( o . Value = = this ) {
continue ;
continue ;
}
}
// || o.GetType().Assembly != Assembly.GetCallingAssembly()
// || o.GetType().Assembly != Assembly.GetCallingAssembly()
IDisposable disposeMe = o as IDisposable ;
IDisposable disposeMe = o . Value as IDisposable ;
if ( disposeMe ! = null ) {
if ( disposeMe ! = null ) {
try {
try {
disposeMe . Dispose ( ) ;
disposeMe . Dispose ( ) ;
@ -51,18 +52,27 @@ namespace ICSharpCode.FormsDesigner.Services
}
}
services . Clear ( ) ;
services . Clear ( ) ;
services = null ;
services = null ;
inDispose = false ;
}
}
#endregion
#endregion
#region System.ComponentModel.Design.IServiceContainer interface implementation
#region System.ComponentModel.Design.IServiceContainer interface implementation
public void RemoveService ( System . Type serviceType , bool promote )
public void RemoveService ( System . Type serviceType , bool promote )
{
{
if ( inDispose )
return ;
serviceContainer . RemoveService ( serviceType , promote ) ;
serviceContainer . RemoveService ( serviceType , promote ) ;
if ( services . Contains ( serviceType ) )
services . Remove ( serviceType ) ;
}
}
public void RemoveService ( System . Type serviceType )
public void RemoveService ( System . Type serviceType )
{
{
if ( inDispose = = true )
return ;
serviceContainer . RemoveService ( serviceType ) ;
serviceContainer . RemoveService ( serviceType ) ;
if ( services . Contains ( serviceType ) )
services . Remove ( serviceType ) ;
}
}
public void AddService ( System . Type serviceType , System . ComponentModel . Design . ServiceCreatorCallback callback , bool promote )
public void AddService ( System . Type serviceType , System . ComponentModel . Design . ServiceCreatorCallback callback , bool promote )
@ -83,7 +93,7 @@ namespace ICSharpCode.FormsDesigner.Services
{
{
if ( IsServiceMissing ( serviceType ) ) {
if ( IsServiceMissing ( serviceType ) ) {
serviceContainer . AddService ( serviceType , serviceInstance , promote ) ;
serviceContainer . AddService ( serviceType , serviceInstance , promote ) ;
services . Add ( serviceInstance ) ;
services . Add ( serviceType , service Instance ) ;
}
}
}
}
@ -91,7 +101,7 @@ namespace ICSharpCode.FormsDesigner.Services
{
{
if ( IsServiceMissing ( serviceType ) ) {
if ( IsServiceMissing ( serviceType ) ) {
serviceContainer . AddService ( serviceType , serviceInstance ) ;
serviceContainer . AddService ( serviceType , serviceInstance ) ;
services . Add ( serviceInstance ) ;
services . Add ( serviceType , service Instance ) ;
}
}
}
}
#endregion
#endregion