Esempio n. 1
0
        /// <summary>
        /// Registers <see cref="IModelMetadataConfiguration"/> classes in IoC
        /// </summary>
        /// <param name="forTypesInAssembly">Assemblies to scan for <see cref="IModelMetadataConfiguration"/> implementations</param>
        /// <param name="registerFoundConfiguration">
        /// Register configuration via IoC container.
        /// <br/>
        /// ------------
        /// <br/><b>Example:</b>
        /// <br/>---<br/>
        /// <br/>Autofac:<br/>
        /// .RegisterConfigurationsWithContainer(r => container.RegisterType(r.MetadataConfigurationType).As(r.InterfaceType))
        /// <br/>---<br/>
        /// Windsor:<br/>
        /// .RegisterConfigurationsWithContainer(r => container.Register(Component.For(r.InterfaceType).ImplementedBy(r.MetadataConfigurationType).LifeStyle.Transient))
        /// </param>
        /// <returns></returns>
        public static ModelMetadataRegistrar RegisterEachConfigurationWithContainer([NotNull] IEnumerable <Assembly> forTypesInAssembly, [NotNull] Action <ConfigurationsScanResult> registerFoundConfiguration)
        {
            Invariant.IsNotNull(forTypesInAssembly, "forTypesInAssembly");
            Invariant.IsNotNull(registerFoundConfiguration, "registerConfigurationWithIoC");

            ConfigurationsScanner
            .GetMetadataClasses(forTypesInAssembly)
            .ForEach(registerFoundConfiguration);
            registredWithContainer = true;
            return(Registrar);
        }
Esempio n. 2
0
        /// <summary>
        /// Registers metadata provider and model metadata configuration classes
        /// </summary>
        public static void Register()
        {
            if (!Registrar.ConfigurationFactoryDefined)
            {
                if (registredWithContainer)
                {
                    ConstructMetadataUsingDependencyResolver();
                }
                else
                {
                    Registrar.ConstructMetadataUsing(
                        () =>
                        ConfigurationsScanner
                        .GetMetadataClasses(From.AllAssemblies())
                        .Select(s => (IModelMetadataConfiguration)Activator.CreateInstance(s.MetadataConfigurationType)));
                }
            }

            Registrar.Register();
        }