Beispiel #1
0
    public static TDomain RegisterDefault <TDomain>(bool initializeReference = true) where TDomain : DomainBase
    {
        DynamicMethod   method = new DynamicMethod("Domain" + Guid.NewGuid().ToString(), typeof(DomainBase), new Type[] { typeof(string) });
        ILGenerator     il     = method.GetILGenerator();
        ConstructorInfo ctor   = typeof(TDomain).GetConstructor(BindingFlags.Instance | BindingFlags.Public, null, new Type[] { typeof(string) }, null);

        il.Emit(OpCodes.Ldarg_0);
        il.Emit(OpCodes.Newobj, ctor);
        il.Emit(OpCodes.Ret);
        CreateDomain = (Func <string, DomainBase>)(method.CreateDelegate(typeof(Func <string, DomainBase>)));

        Default = Create("Default");
        if (initializeReference)
        {
            foreach (var asm in DependencyContext
                     .Default
                     .CompileLibraries
                     .SelectMany(cl => cl.ResolveReferencePaths()))
            {
                Default.AddReferencesFromDllFile(asm);
            }
        }



        return((TDomain)Default);
    }
Beispiel #2
0
    public static TDomain RegisterDefault <TDomain>() where TDomain : DomainBase <TDomain>, new()
    {
        if (Default != null)
        {
            if (typeof(TDomain) != Default.GetType())
            {
                Default = (new TDomain()).GetInstance("Default");
            }
        }
        else
        {
            Default = (new TDomain()).GetInstance("Default");
        }


        foreach (var asm in DependencyContext
                 .Default
                 .CompileLibraries
                 .SelectMany(cl => cl.ResolveReferencePaths()))
        {
            Default.AddReferencesFromDllFile(asm);
        }


        return((TDomain)Default);
    }