Clemens Vasters: Enterprise Development & Alien Abductions
Thoughts about Microsoft .NET, Enterprise Services, XML and other dull and boring things.
Updated: 7/30/2002; 8:47:46 AM.

 














Subscribe to "Clemens Vasters: Enterprise Development & Alien Abductions" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.

 
 

Tuesday, July 16, 2002

Arrogance is a design pattern for asynchronously decoupled systems. "If you give me an XML schema and the data I give you is valid according to that schema, it's your problem and job to process it properly. Not mine." Synchronicity is for people who worry too much about other people's problems. If a remote system fails processing data that was perfectly valid according to its own rules, what are you doing with that returned failure code? Panic? Call your mom?
11:10:43 PM      comment []

Solving the Enterprise Services config dilemma. Here's a little variation of System.EnterpriseServices.ServicedComponent that activates classes derived from ServicedComponentEx in a freely configurable, non-default app-domain and roots them in the directory of the assembly containing the component and not system32. TODO: Add support for custom config files based on COM+ package name, proper security setup, etc; Still, I am tired, so I am posting anyways ;) G'night.

using System; using System.Runtime.InteropServices; 
using System.EnterpriseServices;
using System.IO;
using System.Reflection;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Proxies;
using System.Runtime.Remoting.Contexts;

namespace newtelligence.EnterpriseServices
{        
[AttributeUsage(AttributeTargets.Class)]    
public class ServicedComponentExProxyAttribute :         
ProxyAttribute, ICustomFactory    
{       
ProxyAttribute _base;       
Type currentType;       
static AppDomain appDomain = null;              


public ServicedComponentExProxyAttribute()       
{
         _base = (ProxyAttribute)typeof(ServicedComponent).GetCustomAttributes(typeof(ProxyAttribute),false)[0];
      }
      public override MarshalByRefObject CreateInstance(Type serverType)
      {
         return _base.CreateInstance(serverType);
      }
      public override RealProxy CreateProxy(ObjRef objRef,Type serverType,object serverObject,Context serverContext)
      {
         return _base.CreateProxy(objRef,serverType,serverObject,serverContext);
      }
      Assembly ResolveHelper(object  o, ResolveEventArgs rargs)
      {
         if ( currentType.Assembly.FullName == rargs.Name )
         {
            return Assembly.LoadFrom(currentType.Assembly.Location);
         }
         else
         {
            return null;
         }
      }
      MarshalByRefObject ICustomFactory.CreateInstance(Type serverType)
        {
         if ( AppDomain.CurrentDomain.FriendlyName == "myappdomain" )
         {
            return ((ICustomFactory)_base).CreateInstance(serverType);
         }
         else
         {
            if ( appDomain == null )
            {
               System.AppDomainSetup appDomainSetup = new AppDomainSetup();
               appDomainSetup.ApplicationBase =
                    Path.Combine(Path.GetPathRoot(serverType.Assembly.Location),
                  Path.GetDirectoryName(serverType.Assembly.Location));
               appDomainSetup.ApplicationName = "complus";
               appDomain = AppDomain.CreateDomain("myappdomain",null,appDomainSetup);
           }
            ResolveEventHandler reh = new ResolveEventHandler(this.ResolveHelper);
            currentType = serverType;
            AppDomain.CurrentDomain.AssemblyResolve += reh;
            MarshalByRefObject mbr = (MarshalByRefObject)appDomain.CreateInstanceFromAndUnwrap(
serverType.Assembly.Location,serverType.FullName);
            AppDomain.CurrentDomain.AssemblyResolve -= reh;
            currentType = null;
            return mbr;
                 }
          }
  }





   [ServicedComponentExProxyAttribute]
   public class ServicedComponentEx : ServicedComponent
   {
      public ServicedComponentEx()
      {
      }
   }
}

12:43:43 AM      comment []


© Copyright 2002 Clemens Vasters.



Click here to visit the Radio UserLand website.

 


Send email to Clemens
July 2002
Sun Mon Tue Wed Thu Fri Sat
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
May   Aug

newtelligence
MSDN Regional Director