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();
        }
Exemple #2
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();
        }