使用应用程序域创建实例 [英] Create instance using app domains

查看:102
本文介绍了使用应用程序域创建实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我是一种从数据库加载所有dll文件及其路径,名称空间以及所有相关类名的方法,并使用所有这些相关信息填充自定义创建的对象,然后使用相关键将其添加到哈希表中.

这是对象的结构:

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:

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;
    }



现在的问题是,每当我必须在该dll中调用一个方法时,它都需要跟踪用户(会话),但是调用该方法意味着必须创建该类的新实例,这将丢失所有数据.反正我可以解决这个问题吗?

方法如下所示:



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:

 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.

推荐答案

使用通过MEF而不是反射的依赖注入.
当请求时,MEF将为您提供单个对象,并且状态将由MEF管理.

在这里看看如何使用MEf和创建Composite应用程序.
http://entensible-application.blogspot.com/ [
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/[^]


这篇关于使用应用程序域创建实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆