Exemplo n.º 1
0
            public DryIocContainerBuilder(
                IEnumerable <Assembly> pluginAssemblies,
                IEnumerable <string> pluginPaths,
                bool dslAspects = false)
            {
                this.DslAspects = dslAspects;
                var container = new DryIoc.Container(rules => rules.With(FactoryMethod.ConstructorWithResolvableArguments)).OpenScopeWithoutContext();

                Proxy = new CastleDynamicProxyProvider();
                this.RegisterSingleton <IMixinProvider>(Proxy);
                this.RegisterSingleton <IDynamicProxyProvider>(Proxy);
                var aopRepository = new AspectRepository(Proxy);

                this.RegisterSingleton <IAspectRegistrator>(aopRepository);
                this.RegisterSingleton <IAspectComposer>(aopRepository);
                this.RegisterSingleton <IInterceptorRegistrator>(aopRepository);
                Factory = new DryIocObjectFactory(container, aopRepository);
                this.RegisterSingleton <IObjectFactory>(Factory);
                this.RegisterSingleton <IServiceProvider>(Factory);
                Plugins = new PluginsConfiguration
                {
                    Directories = (pluginPaths ?? new string[0]).ToList(),
                    Assemblies  = (pluginAssemblies ?? new Assembly[0]).ToList()
                };
                this.RegisterSingleton(Plugins);
                this.RegisterType <SystemInitialization>();
                this.RegisterType(typeof(PluginRepository <>), InstanceScope.Singleton, true, typeof(IPluginRepository <>));
                var types = AssemblyScanner.GetAllTypes();

                this.RegisterSingleton <IExtensibilityProvider>(new DryIocMefProvider(Plugins, Proxy, container));
                DryIocObjectFactory.RegisterToContainer(container, this);
            }
Exemplo n.º 2
0
 public AutofacMefProvider(
     PluginsConfiguration configuration,
     IMixinProvider mixinProvider,
     ILifetimeScope container)
     : base(mixinProvider, new AutofacResolution(container, configuration))
 {
 }
Exemplo n.º 3
0
        internal static List <Assembly> FindPlugins(PluginsConfiguration configuration)
        {
            var assemblies = new List <Assembly>();

            if (configuration.Directories.Count == 0 && configuration.Assemblies.Count == 0)
            {
                var rootPath = AppDomain.CurrentDomain.BaseDirectory ?? typeof(AutofacMefProvider).Assembly.Location;
                foreach (var f in Directory.GetFiles(rootPath, "*.Plugins.*.dll", SearchOption.TopDirectoryOnly))
                {
                    try { assemblies.Add(Assembly.LoadFrom(f)); }
                    catch (Exception aex)
                    {
                        System.Diagnostics.Debug.WriteLine(aex.ToString());
                        throw new FrameworkException("Error loading plugin: " + f, aex);
                    }
                }
            }

            foreach (var directory in configuration.Directories)
            {
                if (directory != null)
                {
                    foreach (var f in Directory.EnumerateFiles(directory, "*.dll"))
                    {
                        try
                        {
                            if (!Plugins.ExcludeFile(f))
                            {
                                var asm = Assembly.LoadFrom(f);
                                if (!Plugins.ExcludeAssembly(asm))
                                {
                                    assemblies.Add(asm);
                                }
                            }
                        }
                        catch (Exception aex)
                        {
                            System.Diagnostics.Debug.WriteLine(aex.ToString());
                            throw new FrameworkException("Error loading plugin: " + f, aex);
                        }
                    }
                }
            }
            foreach (var asm in configuration.Assemblies)
            {
                if (asm != null)
                {
                    assemblies.Add(asm);
                }
            }
            return(assemblies);
        }
Exemplo n.º 4
0
        internal static List <Assembly> FindPlugins(PluginsConfiguration configuration)
        {
            var assemblies = new List <Assembly>();

            if (configuration.Directories.Count == 0 && configuration.Assemblies.Count == 0)
            {
                var rootPath = AppDomain.CurrentDomain.BaseDirectory ?? typeof(AutofacMefProvider).Assembly.Location;
                foreach (var f in Directory.GetFiles(rootPath, "*.Plugins.*.dll", SearchOption.TopDirectoryOnly))
                {
                    try { assemblies.Add(Assembly.LoadFrom(f)); }
                    catch (Exception aex)
                    {
                        System.Diagnostics.Debug.WriteLine(aex.ToString());
                        throw new FrameworkException("Error loading plugin: " + f, aex);
                    }
                }
            }
            foreach (var directory in configuration.Directories)
            {
                if (directory != null)
                {
                    foreach (var f in Directory.GetFiles(directory, "*.dll", SearchOption.TopDirectoryOnly))
                    {
                        var name = Path.GetFileNameWithoutExtension(f);
                        //TODO: temporary hack, will clean up later
                        if (name != "Oracle.DataAccess" && name != "Revenj.DatabasePersistence.Oracle")
                        {
                            try { assemblies.Add(Assembly.LoadFrom(f)); }
                            catch (Exception aex)
                            {
                                System.Diagnostics.Debug.WriteLine(aex.ToString());
                                throw new FrameworkException("Error loading plugin: " + f, aex);
                            }
                        }
                    }
                }
            }
            foreach (var asm in configuration.Assemblies)
            {
                if (asm != null)
                {
                    assemblies.Add(asm);
                }
            }
            return(assemblies);
        }
Exemplo n.º 5
0
 public AutofacResolution(ILifetimeScope container, PluginsConfiguration configuration)
 {
     this.Container = container.BeginLifetimeScope(builder =>
     {
         try
         {
             var assemblies = FindPlugins(configuration);
             foreach (var asm in assemblies)
             {
                 builder.RegisterComposablePartCatalog(new AssemblyCatalog(asm));
             }
         }
         catch (System.Reflection.ReflectionTypeLoadException ex)
         {
             var sb = new StringBuilder();
             foreach (var le in ex.LoaderExceptions.Take(5))
             {
                 sb.AppendLine(le.Message);
                 var fle = le as FileLoadException;
                 if (fle != null && fle.FusionLog != null)
                 {
                     sb.AppendLine(fle.FusionLog);
                 }
             }
             System.Diagnostics.Debug.WriteLine(ex.ToString());
             var firstFive = sb.ToString();
             System.Diagnostics.Debug.WriteLine(firstFive);
             throw new FrameworkException("Error loading plugins. Can't load plugins. " + firstFive, ex);
         }
         catch (FrameworkException) { throw; }
         catch (Exception ex)
         {
             System.Diagnostics.Debug.WriteLine(ex.ToString());
             throw new FrameworkException("Error loading plugins.", ex);
         }
     });
 }