private static void SetupExtensibility(Revenj.Extensibility.Autofac.ContainerBuilder builder, bool withAspects, bool externalConfiguration)
        {
            var dynamicProxy = new CastleDynamicProxyProvider();
            var aopRepository = new AspectRepository(dynamicProxy);

            var dllPlugins = externalConfiguration == false ? new string[0] :
                (from key in ConfigurationManager.AppSettings.AllKeys
                 where key.StartsWith("PluginsPath", StringComparison.OrdinalIgnoreCase)
                 let path = ConfigurationManager.AppSettings[key]
                 let pathRelative = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, path)
                 let chosenPath = Directory.Exists(pathRelative) ? pathRelative : path
                 select chosenPath)
                .ToArray();

            var assemblies = Revenj.Utility.AssemblyScanner.GetAssemblies().Where(it => it.FullName.StartsWith("Revenj."));
            builder.RegisterInstance(new PluginsConfiguration { Assemblies = assemblies, Directories = dllPlugins });

            builder.RegisterType<SystemInitialization>();
            builder.RegisterType<AutofacObjectFactory>().As<IObjectFactory>().SingleInstance();
            builder.RegisterType<AutofacMefProvider>().As<IExtensibilityProvider>().SingleInstance();
            builder.RegisterGeneric(typeof(PluginRepository<>)).As(typeof(IPluginRepository<>)).SingleInstance();

            builder.RegisterInstance(aopRepository).As<IAspectRegistrator, IAspectComposer, IInterceptorRegistrator>();
            builder.RegisterInstance(dynamicProxy).As<IMixinProvider, IDynamicProxyProvider>();

            var types = AssemblyScanner.GetAllTypes();//TODO: force load everything
            if (withAspects)
            {
                foreach (var m in types)
                {
                    if (m.Assembly.FullName.StartsWith("Revenj."))
                        continue;
                    if (m.IsPublic && !m.IsAbstract && typeof(Revenj.Extensibility.Autofac.Module).IsAssignableFrom(m) && m.GetConstructor(new Type[0]) != null)
                        builder.RegisterModule((Revenj.Extensibility.Autofac.Module)Activator.CreateInstance(m));
                }
                builder.RegisterModule(new AspectsModule(aopRepository));
            }
        }
        private static void SetupExtensibility(Revenj.Extensibility.Autofac.ContainerBuilder builder)
        {
            var dynamicProxy = new CastleDynamicProxyProvider();
            var aopRepository = new AspectRepository(dynamicProxy);

            var dllPlugins =
                (from key in ConfigurationManager.AppSettings.AllKeys
                 where key.StartsWith("PluginsPath", StringComparison.OrdinalIgnoreCase)
                 let path = ConfigurationManager.AppSettings[key]
                 let pathRelative = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, path)
                 let chosenPath = Directory.Exists(pathRelative) ? pathRelative : path
                 select chosenPath)
                .ToList();
            builder.RegisterInstance(new PluginsConfiguration { Directories = dllPlugins });

            builder.RegisterType<SystemInitialization>();
            builder.RegisterType<AutofacObjectFactory>().As<IObjectFactory>().SingleInstance();
            builder.RegisterType<AutofacMefProvider>().As<IExtensibilityProvider>().SingleInstance();
            builder.RegisterGeneric(typeof(PluginRepository<>)).As(typeof(IPluginRepository<>)).SingleInstance();

            builder.RegisterInstance(aopRepository).As<IAspectRegistrator, IAspectComposer, IInterceptorRegistrator>();
            builder.RegisterInstance(dynamicProxy).As<IMixinProvider, IDynamicProxyProvider>();

            if (ConfigurationManager.AppSettings["Revenj.AllowAspects"] == "true")
                builder.RegisterModule(new AspectsModule(aopRepository));
        }
        private static void SetupPostgres(Revenj.Extensibility.Autofac.ContainerBuilder builder, string cs)
        {
            builder.RegisterInstance(new Revenj.DatabasePersistence.Postgres.ConnectionInfo(cs));
            builder.RegisterType<PostgresConnectionPool>().As<IConnectionPool>().SingleInstance();
            builder.RegisterType<PostgresQueryManager>().As<IDatabaseQueryManager>().InstancePerLifetimeScope();
            builder.RegisterType<PostgresDatabaseQuery>().As<IPostgresDatabaseQuery>();
            builder.Register(c => c.Resolve<IDatabaseQueryManager>().CreateQuery()).As<IDatabaseQuery>().InstancePerLifetimeScope();
            builder.RegisterType<PostgresDatabaseNotification>().As<IDataChangeNotification, IEagerNotification>().SingleInstance();

            builder.RegisterType<PostgresObjectFactory>().As<IPostgresConverterRepository, IPostgresConverterFactory>().SingleInstance();

            builder.RegisterType<Revenj.DatabasePersistence.Postgres.QueryGeneration.QueryExecutor>();
        }
        private static void SetupPostgres(Revenj.Extensibility.Autofac.ContainerBuilder builder)
        {
            var cs = ConfigurationManager.AppSettings["Revenj.ConnectionString"] ?? ConfigurationManager.AppSettings["ConnectionString"];
            if (string.IsNullOrEmpty(cs))
                throw new ConfigurationErrorsException(@"ConnectionString is missing from configuration. Add ConnectionString to <appSettings>
            Example: <add key=""ConnectionString"" value=""server=postgres.localhost;port=5432;database=MyDatabase;user=postgres;password=123456;encoding=unicode"" />");

            builder.RegisterInstance(new Revenj.DatabasePersistence.Postgres.ConnectionInfo(cs));
            builder.RegisterType<PostgresConnectionPool>().As<IConnectionPool>().SingleInstance();
            builder.RegisterType<PostgresQueryManager>().As<IDatabaseQueryManager>().InstancePerLifetimeScope();
            builder.RegisterType<PostgresDatabaseQuery>().As<IPostgresDatabaseQuery>();
            builder.Register(c => c.Resolve<IDatabaseQueryManager>().CreateQuery()).As<IDatabaseQuery>().InstancePerLifetimeScope();
            builder.RegisterType<PostgresDatabaseNotification>().As<IDataChangeNotification, IEagerNotification>().SingleInstance();

            builder.RegisterType<PostgresObjectFactory>().As<IPostgresConverterRepository, IPostgresConverterFactory>().SingleInstance();

            builder.RegisterType<Revenj.DatabasePersistence.Postgres.QueryGeneration.QueryExecutor>();
        }