I m 采用结构图,自动向我的保存构造注入数据。 I m给出了名字(例如“项目1”),我需要动态地创建项目保存人的榜样。
I m 采用标准命名公约,因此我知道“项目1DataContext”。 我曾设法利用思考,对我的“项目1DataContext”进行论证,但是它属于一种物体类型。 问题在于,我需要把项目1DataContext Object带入我的保存人,以树立一个榜样。 我如何利用思考来做到这一点? 能否通过某种手段来投放物体?
Assembly myDataContextAssembly = typeof(SomeTypeInTheAssembly).Assembly;
Type dataContextType = myDataContextAssembly.GetType(ProjectName + "DataContext");
object dataContext = Activator.CreateInstance(dataContextType);
// I need to cast the data context here
IRepository<Project1DataContext> = new Repository<Project1DataContext>(dataContext)
In the mean time, I will use an if statement, but this is not a viable solution if I have 100+ projects. I need to do this using reflection and ideally having structure map determine the types and injecting them for me.