Click here to Skip to main content
15,897,032 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi
I a method that loads all of the dll files and their paths, namespaces as well as all the relevant class names from a database and fills a custom created object with all of these relevant information, which then gets added to a hashtable with a relevant key.

here is the structure of the object:

C#
public class AppDomObject
    {
        public AppDomain campaignDomain;
        public AssemblyName assemblyName;
        public Assembly campignAssembly;

        public string Path;
        public string nameSpace;
        public string ClassName;

        public Type type;

        public MethodInfo methodInfo;
    }


Now the problem is that whenever I have to call a method in that dll, it needs to keep track (Sessions) of the user, but calling the method means that a new instance of the class has to be created, which loses all of the data. Is there anyway I can work around this?

The method is shown below:

C#
 AppDomObject refObject = (AppDomObject)AppDomainHolder.RunningDomains[USSD_String];
classInstance = Activator.CreateInstance(refObject.type, null);
                
refObject.methodInfo = refObject.type.GetMethod("SomeMethod");
object result = refObject.methodInfo.Invoke(classInstance, new object[] { req.msisdn, req.request });


Thanks in advance for any help.
Posted

1 solution

Use Dependency injection using MEF rather than reflection.
MEF will give you a single object when requested and the state will be managed by MEF.

Have a look at how to use MEf and to create Composite application here.
http://entensible-application.blogspot.com/[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900