Exemplo n.º 1
0
        private static void SetupExtensibility(Autofac.ContainerBuilder builder, bool withAspects)
        {
            var dynamicProxy = new CastleDynamicProxyProvider();
            var aopRepository = new AspectRepository(dynamicProxy);

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

            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 (withAspects)
            {
                foreach (var m in AssemblyScanner.GetAllTypes())
                {
                    if (m.IsPublic && typeof(Autofac.Module).IsAssignableFrom(m) && m.GetConstructor(new Type[0]) != null)
                        builder.RegisterModule((Autofac.Module)Activator.CreateInstance(m));
                }
                builder.RegisterModule(new AspectsModule(aopRepository));
            }
        }
Exemplo n.º 2
0
        protected override void Load(Autofac.ContainerBuilder builder)
        {
            builder.RegisterInstance<ISessionFactory>(CreateSessionFactory()).SingleInstance();

            builder.Register(p => new QuickFramework.NHibenateRepository.Impl
               .NHibernateUnitOfWork(p.Resolve<ISessionFactory>()))
               .As<QuickFramework.UnitOfWork.IUnitOfWork>();

            builder.RegisterGeneric(typeof(QuickFramework.NHibenateRepository.NHibernateRepository<>))
                   .As(typeof(QuickFramework.Repository.IRepository<>));

            builder.RegisterGeneric(typeof(QuickFramework.Caching.MongoDBCacheRepository.MongoDBCacheRepository<,>))
                   .As(typeof(QuickFramework.Caching.ICacheRepository<,>))
                      .WithParameters(
                          new NamedParameter[]{
                          new NamedParameter("connectionstr","mongodb://localhost"),
                          new NamedParameter("databasename","Test"),
                          new NamedParameter("collectionname","UserDTO")
                              });
        }
Exemplo n.º 3
0
        private static void SetupExtensibility(Autofac.ContainerBuilder builder)
        {
            var dynamicProxy = new CastleDynamicProxyProvider();
            var aopRepository = new AspectRepository(dynamicProxy);

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

            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>();
        }
Exemplo n.º 4
0
        private static void SetupPatterns(Autofac.ContainerBuilder builder)
        {
            var serverModels =
                (from asm in NGS.Utility.AssemblyScanner.GetAssemblies()
                 let type = asm.GetType("SystemBoot.Configuration")
                 where type != null && type.GetMethod("Initialize") != null
                 select asm)
                .ToList();

            builder.RegisterGeneratedFactory<NGS.DomainPatterns.DomainModel.Factory>();
            builder.RegisterType<NGS.DomainPatterns.DomainModel>();
            builder.Register(c => c.Resolve<NGS.DomainPatterns.DomainModel.Factory>()(serverModels)).As<IDomainModel>().SingleInstance();
            builder.RegisterType<DomainTypeResolver>().As<ITypeResolver>().SingleInstance();
            builder.RegisterType<ServiceLocator>().As<IServiceLocator, IServiceProvider>().InstancePerLifetimeScope();
            builder.RegisterGeneric(typeof(WeakCache<>)).As(typeof(IDataCache<>)).InstancePerLifetimeScope();
            builder.RegisterType<DomainEventSource>().As<IDomainEventSource>().InstancePerLifetimeScope();
            builder.RegisterType<DomainEventStore>().As<IDomainEventStore>().InstancePerLifetimeScope();
            builder.RegisterGeneric(typeof(SingleDomainEventSource<>)).As(typeof(IDomainEventSource<>)).InstancePerLifetimeScope();
            builder.RegisterGeneric(typeof(RegisterChangeNotifications<>)).As(typeof(IObservable<>)).SingleInstance();
        }
Exemplo n.º 5
0
        private static void SetupExtensibility(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>();
        }
Exemplo n.º 6
0
        private static void SetupPatterns(Autofac.ContainerBuilder builder)
        {
            var serverModels =
                (from key in ConfigurationManager.AppSettings.AllKeys
                 where key.StartsWith("ServerAssembly", StringComparison.OrdinalIgnoreCase)
                 select LoadAssembly(ConfigurationManager.AppSettings[key]))
                .ToList();

            if (serverModels.Count == 0)
            {
                serverModels =
                    (from asm in NGS.Utility.AssemblyScanner.GetAssemblies()
                     let type = asm.GetType("SystemBoot.Configuration")
                     where type != null && type.GetMethod("Initialize") != null
                     select asm)
                    .ToList();
                if (serverModels.Count == 0)
                    throw new ConfigurationErrorsException(@"Server assemblies not found. When running in compiled mode, server assemblies must be deployed with other assemblies.
            Alternatively, explicitly specify sever assembly in the config file.
            Example: <add key=""ServerAssembly_Domain"" value=""AppDomainModel.dll"" />");
            }

            builder.RegisterGeneratedFactory<NGS.DomainPatterns.DomainModel.Factory>();
            builder.RegisterType<NGS.DomainPatterns.DomainModel>();
            builder.Register(c => c.Resolve<NGS.DomainPatterns.DomainModel.Factory>()(serverModels)).As<IDomainModel>().SingleInstance();
            builder.RegisterType<DomainTypeResolver>().As<ITypeResolver>().SingleInstance();
            builder.RegisterType<ServiceLocator>().As<IServiceLocator, IServiceProvider>().InstancePerLifetimeScope();
            builder.RegisterGeneric(typeof(WeakCache<>)).As(typeof(IDataCache<>)).InstancePerLifetimeScope();
            builder.RegisterType<DomainEventSource>().As<IDomainEventSource>().InstancePerLifetimeScope();
            builder.RegisterType<DomainEventStore>().As<IDomainEventStore>().InstancePerLifetimeScope();
            builder.RegisterGeneric(typeof(SingleDomainEventSource<>)).As(typeof(IDomainEventSource<>)).InstancePerLifetimeScope();
            builder.RegisterGeneric(typeof(RegisterChangeNotifications<>)).As(typeof(IObservable<>)).SingleInstance();
        }