public Type[] GetControllerTypes(IEnumerable <ServiceInfo> services)
        {
            var result = _webApiGenerator.Generate(services);

            DynamicAssembly assembly = new DynamicAssembly(_eventHub);

            assembly.AppendSourceUnits(result);
            assembly.AddWebApiReferences();

            AssemblyPurpose p = AssemblyPurpose.Handlers | AssemblyPurpose.Commands | AssemblyPurpose.Queries |
                                AssemblyPurpose.Results;

            assembly.AddReferenceFrom(_dynamicPool.Where(x => (x.Purpose & p) > 0).Select(x => x.Assembly));

            _dynamicPool.AddOrReplace(assembly);

            assembly.Compile();


            var controllerTypes = assembly.Assembly.GetTypes()
                                  .Where(x => typeof(ControllerBase).IsAssignableFrom(x))
                                  .ToArray();

            return(controllerTypes);
        }
Exemplo n.º 2
0
        public DynamicAssembly Merge(IEnumerable <SourceUnit> units, AssemblyPurpose referencePurposes = AssemblyPurpose.None)
        {
            //TODO: Rething this...

            var newOnes = units.Except(_assemblies.SelectMany(x => x.SourceUnits));

            if (newOnes.Any())
            {
                DynamicAssembly n = new DynamicAssembly(_eventHub);

                n.AddReferenceFrom(_assemblies.First().References);
                n.AppendSourceUnits(newOnes);
                if (referencePurposes != AssemblyPurpose.None)
                {
                    var refs = _assemblies.Where(x => (x.Purpose & referencePurposes) > 0)
                               .Select(x => x.Assembly)
                               .ToArray();
                    n.AddReferenceFrom(refs);
                }
                this._assemblies.AddFirst(n);
                return(n.Compile());
            }
            else
            {
                return(_assemblies.First());
            }
        }