public void Configure(IExportRegistrationBlock builder) { var profiles = typeof(GithubAuthentication) .Assembly .GetTypes() .Where(p => typeof(Profile).IsAssignableFrom(p)); foreach (var profile in profiles) { builder.Export(profile).As(typeof(Profile)); } builder.ExportInstance((scope, context) => new MapperConfiguration(cfg => { cfg.ConstructServicesUsing(scope.Locate); foreach (var profile in scope.Locate <IEnumerable <Profile> >()) { cfg.AddProfile(profile); } })) .As <MapperConfiguration>() .Lifestyle.Singleton(); builder.ExportInstance((scope, context) => new Mapper(scope.Locate <MapperConfiguration>())) .As <IMapper>() .Lifestyle.Singleton(); }
public static void ProxyNamespace(this IExportRegistrationBlock block, ProxyNamespaceConfig config) { // I mark everything as -1 priority so that if another version is registered it overrides these defaults block.Export <ProxyGenerator.ProxyGenerator>().As <IProxyGenerator>().WithPriority(-1).Lifestyle.Singleton().IfNotRegistered(typeof(IProxyGenerator)); block.Export <DefaultNamingConventionService>().As <INamingConventionService>().WithPriority(-1).IfNotRegistered(typeof(INamingConventionService)); block.ExportFactory(() => new DefaultRpcClientProvider(config.Url ?? "ReplaceMe")).As <IRpcHttpClientProvider>().WithPriority(-1).IfNotRegistered(typeof(IRpcHttpClientProvider)); block.Export <JsonMethodObjectWriter>().As <IJsonMethodObjectWriter>().Lifestyle.Singleton().WithPriority(-1).IfNotRegistered(typeof(JsonMethodObjectWriter)); block.Export <RpcProxyService>().As <IRpcProxyService>().WithPriority(-1).Lifestyle.SingletonPerScope().IfNotRegistered(typeof(IRpcProxyService)); var serializerRegistration = block.Export <JsonSerializer>().WithPriority(-1).Lifestyle.Singleton().IfNotRegistered(typeof(JsonSerializer)); if (config.SerializerInit != null) { serializerRegistration.Apply(config.SerializerInit); } if (config.UseDataContext) { block.Export <DataContextHeaderProcessor>().As <IRpcContextHeader>().As <IHeaderProcessor>().WithPriority(-1).Lifestyle.SingletonPerScope().IfNotRegistered(typeof(IHeaderProcessor)); } var compressionPicker = new DefaultMethodCompressionPicker(config.CompressRequest, config.CompressResponse); block.AddMissingExportStrategyProvider(new ProxyStrategyProvider(config.CallByName, compressionPicker, config.Namespaces)); }
/// <summary> /// Create and configure a new registration block for tenants container configuration. /// </summary> /// <typeparam name="TTenant">Tenant Type.</typeparam> /// <param name="config"></param> /// <param name="tenants"></param> /// <param name="configure"></param> /// <returns></returns> public static IExportRegistrationBlock ForTenants <TTenant>(this IExportRegistrationBlock config, IEnumerable <TTenant> tenants, Action <TenantsContainerBuilder <TTenant> > configure ) where TTenant : ITenant { var tenantsContainerBuilder = new TenantsContainerBuilder <TTenant>(); configure(tenantsContainerBuilder); var configs = tenantsContainerBuilder.GetAll(); foreach (var tenant in tenants) { foreach (var tenantConfig in configs) { if (tenantConfig.TenantFilter != null && !tenantConfig.TenantFilter(tenant)) { continue; } tenantConfig.Configure(new TenantContainerBuilder <TTenant>(config, tenant)); } } return(config); }
public void Configure(IExportRegistrationBlock block) { foreach (var taskType in TaskTypes) { block.ExportFactory((Func <Type, object> locator) => new Function(taskType, locator)).As <IFunction>(); } }
public override void Configure(IExportRegistrationBlock block) { block.ExportModuleScope <DepartmentTableModel>(); block.ExportModuleScope <DepartmentTable>() .ImportProperty(v => v.ModuleToken) .ImportProperty(v => v.ViewModel); }
public override void Configure(IExportRegistrationBlock registrationBlock) { registrationBlock.ExportModuleScope <DisciplineFormModel>(); registrationBlock.ExportModuleScope <DisciplineForm>() .ImportProperty(form => form.ViewModel) .ImportProperty(form => form.ModuleToken); }
public void Configure(IExportRegistrationBlock block) { block.Export <PhoneInfoReader>().As <IPhoneInfoReader>().Lifestyle.Singleton(); block.Export <PhoneModelInfoInfoReader>().As <IPhoneModelInfoReader>().Lifestyle.Singleton(); block.Export <Lumia.Phone>().As <IPhone>().Lifestyle.Singleton(); block.Export <DiskRoot>().As <IDiskRoot>().Lifestyle.Singleton(); }
private static void RegisterType( Type registrationType, Type implementationType, Lifetime lifetime, IExportRegistrationBlock registry) { switch (lifetime) { case Lifetime.Transient: registry.Export(implementationType) .As(registrationType); break; case Lifetime.Singleton: registry.Export(implementationType) .As(registrationType) .Lifestyle.Singleton(); break; case Lifetime.PerRequest: registry.Export(implementationType) .As(registrationType) .Lifestyle.SingletonPerRequest(); break; default: throw new ArgumentOutOfRangeException("lifetime", lifetime, $"Unknown Lifetime: {lifetime}."); } }
public override void Configure(IExportRegistrationBlock block) { block.ExportModuleScope <StudentViewPageModel>(); block.ExportModuleScope <StudentViewPage>() .ImportProperty(v => v.ModuleToken) .ImportProperty(v => v.ViewModel); }
/// <summary> /// Intercept interface or abstract /// </summary> /// <typeparam name="TService"></typeparam> /// <typeparam name="TInterceptor"></typeparam> /// <param name="block"></param> /// <returns></returns> public static IFluentDecoratorStrategyConfiguration Intercept <TService, TInterceptor>( this IExportRegistrationBlock block) where TInterceptor : IInterceptor { Type decoratorType; var tService = typeof(TService); if (tService.GetTypeInfo().IsInterface) { decoratorType = ProxyBuilder.CreateInterfaceProxyTypeWithTargetInterface(tService, new Type[0], ProxyGenerationOptions.Default); } else if (tService.GetTypeInfo().IsClass) { decoratorType = ProxyBuilder.CreateClassProxyTypeWithTarget(tService, new Type[0], ProxyGenerationOptions.Default); } else { throw new Exception("Service type must be interface or class"); } return (block.ExportDecorator(decoratorType) .As(tService) .WithCtorParam <TInterceptor, IInterceptor[]>(i => new IInterceptor[] { i })); }
public void Configure(IExportRegistrationBlock block) { block.Export <PhoneModelInfoInfoReader>().As <IPhoneModelInfoReader>(); block.Export <PhoneInfoReader>().As <IPhoneInfoReader>(); block.Export <LumiaContextualizer>().As <IContextualizer>(); //block.Export<LumiaDetector>().As<IDetector>(); }
/// <summary> /// Excludes type from auto registration based on name. * at the front or back of name will be treated as wildcard /// </summary> /// <param name="block"></param> /// <param name="typeName"></param> /// <returns></returns> public static IExportRegistrationBlock ExcludeTypeFromAutoRegistration(this IExportRegistrationBlock block, string typeName) { var provider = (IConcreteExportStrategyProvider) block.OwningScope.MissingExportStrategyProviders.FirstOrDefault(p => p is IConcreteExportStrategyProvider); provider?.AddFilter(t => { if (typeName.StartsWith("*")) { if (typeName.EndsWith("*")) { return(t.FullName.Contains(typeName.Replace("*", ""))); } return(t.FullName.EndsWith(typeName.Replace("*", ""))); } if (typeName.EndsWith("*")) { return(t.FullName.StartsWith(typeName.Replace("*", ""))); } return(t.FullName == typeName); }); return(block); }
public void Configure(IExportRegistrationBlock registrationBlock) { registrationBlock.Export(AllTypes()) .BasedOn <IController>() .ByType() .ExternallyOwned(); }
public override void Configure(IExportRegistrationBlock block) { block.ExportModuleScope <LessonForm>() .ImportProperty(v => v.ModuleToken) .ImportProperty(v => v.ViewModel); block.ExportModuleScope <LessonFormModel>(); }
public static IExportRegistrationBlock WithCommon(this IExportRegistrationBlock block, WindowsDeploymentOptionsProvider installOptionsProvider) { var taskTypes = from a in Assemblies.AppDomainAssemblies from type in a.ExportedTypes where type.GetTypeInfo().ImplementedInterfaces.Contains(typeof(IDeploymentTask)) select type; block.ExportAssemblies(Assemblies.AppDomainAssemblies).ByInterface <ISpaceAllocator <IDevice> >(); block.Export <ZipExtractor>().As <IZipExtractor>(); block.ExportFactory(Tokenizer.Create).As <Tokenizer <LangToken> >(); block.Export <ScriptParser>().As <IScriptParser>(); block.ExportFactory(() => installOptionsProvider).As <IWindowsOptionsProvider>(); block.Export <WoaDeployer>().As <IWoaDeployer>(); block.Export <BootCreator>().As <IBootCreator>(); block.Export <LowLevelApi>().As <ILowLevelApi>(); block.ExportInstance(taskTypes).As <IEnumerable <Type> >(); block.Export <ScriptRunner>().As <IScriptRunner>(); block.Export <InstanceBuilder>().As <IInstanceBuilder>(); block.Export <RaspberryPathBuilder>().As <IPathBuilder>(); block.Export <FileSystemOperations>().As <IFileSystemOperations>(); block.Export <BcdInvokerFactory>().As <IBcdInvokerFactory>(); block.Export <WindowsDeployer>().As <IWindowsDeployer>(); block.Export <RaspberryDisklayoutPreparer>().As <IDiskLayoutPreparer>(); block.Export <ImageFlasher>().As <IImageFlasher>(); block.Export <DismImageService>().As <IWindowsImageService>(); block.ExportFactory(() => AzureDevOpsClient.Create(new Uri("https://dev.azure.com"))).As <IAzureDevOpsBuildClient>(); return(block); }
public override void Configure(IExportRegistrationBlock block) { block.ExportModuleScope <SimpleEffectsMiddleware <GlobalState> >(); block.ExportModuleScope <Storage>(); block.ExportModuleScope <MainReducer>(); block.ExportModuleScope <SerialUtil>(); block.ExportModuleScope <StudentCardService>(); block.ExportModuleScope <PhotoService>(); block.ExportModuleScope <AudioService>(); block.ExportModuleScope <ModuleActivator>(); block.ExportModuleScope <WindowPageHost>().As <IPageHost>(); block.ExportModuleScope <TimerService <LessonInterval, AlarmEvent> >(); block.ExportModuleScope <DatabaseBackupService>(); var notifier = new Notifier(configuration => { configuration.PositionProvider = new PrimaryScreenPositionProvider(Corner.BottomRight, 10, 10); configuration.LifetimeSupervisor = new TimeAndCountBasedLifetimeSupervisor( TimeSpan.FromMilliseconds(5000), MaximumNotificationCount.FromCount(5)); configuration.Dispatcher = Application.Current.Dispatcher; }); block.ExportInstance(notifier); }
private static IExportRegistrationBlock WithRealPhone(this IExportRegistrationBlock block) { block.Export <PhoneModelReader>().As <IPhoneModelReader>(); block.Export <Phone>().As <IPhone>().As <IDevice>(); block.Export <DismImageService>().As <IWindowsImageService>(); return(block); }
private static IExportRegistrationBlock WithRealPhone(this IExportRegistrationBlock block) { block.Export <PhoneModelInfoInfoReader>().As <IPhoneModelInfoReader>().Lifestyle.Singleton(); block.Export <Phone>().As <IPhone>().Lifestyle.Singleton(); block.Export <DismImageService>().As <IWindowsImageService>().Lifestyle.Singleton(); return(block); }
public void Configure(IExportRegistrationBlock registrationBlock) { var assembly = System.Reflection.Assembly.Load("BusinessSolutions.Common.Infra"); registrationBlock.ExportAssembly(assembly) .ByInterfaces(); assembly = System.Reflection.Assembly.Load("CommonSettings.DAL"); registrationBlock.ExportAssembly(assembly) .ExportAttributedTypes(); assembly = System.Reflection.Assembly.Load("CommonSettings.BLL"); registrationBlock.ExportAssembly(assembly) .ExportAttributedTypes(); assembly = System.Reflection.Assembly.Load("Sanabel.Security.Infra"); registrationBlock.ExportAssembly(assembly).ByInterfaces(c => c.Name.EndsWith("Repository") || c.Name.EndsWith("UnitOfWork")); assembly = System.Reflection.Assembly.Load("Security.AspIdentity"); registrationBlock.ExportAssembly(assembly) .ByInterfaces(); assembly = System.Reflection.Assembly.Load("Sanabel.Security.Application"); registrationBlock.ExportAssembly(assembly) .ByInterfaces(); assembly = System.Reflection.Assembly.Load("Sanable.Cases.Infra"); registrationBlock.ExportAssembly(assembly) .ByInterfaces(); assembly = System.Reflection.Assembly.Load("Sanabel.Cases.App"); registrationBlock.ExportAssembly(assembly) .ByInterfaces(); assembly = System.Reflection.Assembly.Load("Sanabel.Volunteers.Infra"); registrationBlock.ExportAssembly(assembly) .ByInterfaces(); assembly = System.Reflection.Assembly.Load("Sanabel.Volunteers.Application"); registrationBlock.ExportAssembly(assembly) .ByInterfaces(); registrationBlock.ExportFactory <IAuthenticationManager>(() => HttpContext.Current.GetOwinContext().Authentication); var logger = NLog.LogManager.CreateNullLogger(); registrationBlock.ExportInstance(logger).As <NLog.ILogger>() .Lifestyle.Singleton(); registrationBlock.ExportAs <AppLogger, ILogger>(); registrationBlock.ExportAssemblyContaining <CompositionRoot>() .BasedOn <Controller>(); registrationBlock.ExportAssemblyContaining <CompositionRoot>() .BasedOn <ApiController>(); }
public void Configure(IExportRegistrationBlock registrationBlock) { registrationBlock.ExportInstance(new ReflectionService()). As <IReflectionService>(); registrationBlock.ExportInstance(new DispatchedMessenger()). As <IDispatchedMessenger>(); }
public override void Configure(IExportRegistrationBlock block) { block.ExportInitialize <IInitializable>(initializable => initializable.Initialize()); block.ExportModuleScope <RegistrationPageModel>(); block.ExportModuleScope <RegistrationPage>() .ImportProperty(v => v.ModuleToken) .ImportProperty(v => v.ViewModel); }
public override void Configure(IExportRegistrationBlock registrationBlock) { registrationBlock.ExportInitialize <IInitializable>(initializable => initializable.Initialize()); registrationBlock.ExportModuleScope <GroupForm>() .ImportProperty(v => v.ModuleToken) .ImportProperty(v => v.ViewModel); registrationBlock.ExportModuleScope <GroupFormModel>(); }
public void Configure(IExportRegistrationBlock registrationBlock) { registrationBlock.Export(AllTypes()) .BasedOn<IController>() .ByType() .ExternallyOwned(); }
public override void Configure(IExportRegistrationBlock block) { block.ExportModuleScope <SchedulePage>() .ImportProperty(page => page.ModuleToken) .ImportProperty(page => page.ViewModel) ; block.ExportModuleScope <SchedulePageModel>(); }
public override void Configure(IExportRegistrationBlock block) { block.ExportModuleScope <TabControllerModel>(); block.ExportModuleScope <TabPageHost>().As <IPageHost>(); block.ExportModuleScope <ModuleActivator>(); block.ExportModuleScope <TabController>() .ImportProperty(v => v.ModuleToken) .ImportProperty(v => v.ViewModel); }
/// <summary> /// Excludes a type from being auto regsitered /// </summary> /// <param name="block"></param> /// <param name="type"></param> /// <returns></returns> public static IExportRegistrationBlock ExcludeTypeFromAutoRegistration(this IExportRegistrationBlock block, Type type) { var provider = (IConcreteExportStrategyProvider) block.OwningScope.MissingExportStrategyProviders.FirstOrDefault(p => p is IConcreteExportStrategyProvider); provider?.AddFilter(t => t.GetTypeInfo().IsAssignableFrom(type.GetTypeInfo())); return(block); }
/// <summary> /// Configure the module /// </summary> /// <param name="registrationBlock">registration block</param> public void Configure(IExportRegistrationBlock registrationBlock) { GraceConfigurationSection graceSection = null; graceSection = ConfigurationManager.GetSection(SectionName) as GraceConfigurationSection; if (graceSection != null) { AssemblyElementCollection assemblies = graceSection.Assemblies; foreach (AssemblyElement assemblyElement in assemblies) { ProcessAssembly(registrationBlock, assemblyElement); } AssemblyDirectoryElementCollection directories = graceSection.Plugins; foreach (AssemblyDirectoryElement assemblyDirectoryElement in directories) { ProcessDirecotry(registrationBlock, assemblyDirectoryElement); } ExportElementCollection exports = graceSection.Exports; if (exports != null) { foreach (ExportElement exportElement in exports) { ProcessExportElement(registrationBlock, exportElement); } } ModuleElementCollection modules = graceSection.Modules; if (modules != null) { foreach (ModuleElement moduleElement in modules) { Type moduleType = ConvertStringToType(moduleElement.Type); if (moduleType != null) { IConfigurationModule configurationModule = (IConfigurationModule)Activator.CreateInstance(moduleType); ConfigureModule(registrationBlock, configurationModule, moduleElement); } else { Logger.Error("Could not locate type: " + moduleElement.Type, "AppConfig"); } } } } }
public void Configure(IExportRegistrationBlock registrationBlock) { registrationBlock.ExportAssembly(typeof(IMigration).Assembly) .Where(y => typeof(IMigration).IsAssignableFrom(y)) .ByInterface <IMigration>() .Lifestyle.Singleton(); registrationBlock.Export <DatabaseManager>().WithCtorCollectionParam <IEnumerable <IMigration>, IMigration>() .Lifestyle.Singleton(); registrationBlock.ExportFactory <DatabaseManager, LocalDbContext>(c => c.Context).ExternallyOwned(); }
public override void Configure(IExportRegistrationBlock block) { block.ExportModuleScope <PageController>() .ImportProperty(controller => controller.ModuleToken) .ImportProperty(controller => controller.ViewModel); block.ExportModuleScope <PageControllerModel>(); block.ExportModuleScope <PageControllerReducer>(); block.ExportModuleScope <PageControllerEffects>(); block.ExportModuleScope <ModuleActivator>(); }
/// <summary> /// Configure the container for StyleMVVM /// </summary> /// <param name="registrationBlock">registration block</param> public void Configure(IExportRegistrationBlock registrationBlock) { SetupDispatchedMessenger(registrationBlock); SetupValidation(registrationBlock); SetupViewModelService(registrationBlock); SetupViewService(registrationBlock); }
public void Configure(IExportRegistrationBlock block) { block.ExportAssemblies(new[] { typeof(MainViewModel).Assembly }) .Where(y => typeof(ISection).IsAssignableFrom(y)) .ByInterface <ISection>() .ByInterface <IBusy>() .ByType() .ExportAttributedTypes() .Lifestyle.Singleton(); }
private void SetupViewModelService(IExportRegistrationBlock registrationBlock) { registrationBlock.Export<ViewModelResolutionService>(). As<IViewModelResolutionService>().AndSingleton(); registrationBlock.Export<ViewModelDataContextBinder>().As<IViewModelBinder>(); registrationBlock.Export<ViewModelLoadedBinder>().As<IViewModelBinder>(); registrationBlock.Export<ViewModelNavigationBinder>().As<IViewModelBinder>(); registrationBlock.Export<ViewModelParentDataContextBinder>().As<IViewModelBinder>(); registrationBlock.Export<ViewModelViewAwareBinder>().As<IViewModelBinder>(); }
/// <summary> /// Export types from a set of assemblies /// </summary> /// <param name="registrationBlock"></param> /// <param name="assemblies">assemblies to export</param> /// <returns></returns> public static IExportTypeSetConfiguration ExportAssemblies(this IExportRegistrationBlock registrationBlock, IEnumerable <Assembly> assemblies) { var types = new List <Type>(); foreach (var assembly in assemblies) { types.AddRange(assembly.ExportedTypes); } return(registrationBlock.Export(types)); }
public void Configure(IExportRegistrationBlock block) { block.Export <ZipExtractor>().As <IZipExtractor>(); block.Export <FileSystemOperations>().As <IFileSystemOperations>().Lifestyle.Singleton(); block.Export <Downloader>().As <IDownloader>().Lifestyle.Singleton(); block.ExportFactory(() => new HttpClient { Timeout = TimeSpan.FromMinutes(30) }).Lifestyle.Singleton(); block.ExportFactory(() => new GitHubClient(new ProductHeaderValue("WOADeployer"))).As <IGitHubClient>().Lifestyle.Singleton(); block.ExportFactory(() => AzureDevOpsBuildClient.Create(new Uri("https://dev.azure.com"))).As <IAzureDevOpsBuildClient>().Lifestyle.Singleton(); }
public void Configure(IExportRegistrationBlock registrationBlock) { registrationBlock.Export<ConventionsService>(). As<IConventionsService>(). AndSingleton(); registrationBlock.Export<ConventionsViewBinder>().As<IViewBinder>(); if (UseViewModelBinder) { registrationBlock.Export<ConventionsViewModelBinder>().As<IViewModelBinder>(); } }
private void SetupViewService(IExportRegistrationBlock registrationBlock) { registrationBlock.Export<NavigationService>(). As<INavigationService>(). WithCtorParam<Frame>().IsRequired(false); registrationBlock.Export<FilePickerService>(). As<IFilePickerService>(). AndSingleton(); #if !NETFX_CORE registrationBlock.Export<PickerLocationIdTranslator>(). As<IPickerLocationIdTranslator>(). AndSingleton(); #endif }
public void Configure(IExportRegistrationBlock registrationBlock) { registrationBlock.Export<BasicService>().As<IBasicService>(); registrationBlock.ExportInstance(IntProperty).AsName("IntProperty"); }
private void ConfigureModule(IExportRegistrationBlock registrationBlock, IConfigurationModule configurationModule, IEnumerable<PropetryElement> element) { foreach (PropetryElement propertyElement in element) { PropertyInfo propertyInfo = configurationModule.GetType().GetRuntimeProperty(propertyElement.Name); if (propertyInfo != null && propertyInfo.CanWrite) { object finalValue = null; if (propertyInfo.PropertyType == typeof(string)) { finalValue = propertyElement.Value; } else { finalValue = Convert.ChangeType(propertyElement.Value, propertyInfo.PropertyType); } if (finalValue != null) { propertyInfo.SetValue(configurationModule, finalValue); } } } configurationModule.Configure(registrationBlock); }
private void ProcessAssembly(IExportRegistrationBlock registrationBlock, AssemblyElement assemblyElement) { AssemblyName assemblyName = AssemblyName.GetAssemblyName(assemblyElement.Path); Assembly newAssembly = Assembly.Load(assemblyName); if (assemblyElement.ScanForAttributes) { registrationBlock.Export(Types.FromAssembly(newAssembly)); } else { ExportInterfaceElementCollection exportInterfaces = assemblyElement.ExportInterfaces; if (exportInterfaces != null && exportInterfaces.Count > 0) { ProcessExportInterfaces(registrationBlock, exportInterfaces, Types.FromAssembly(newAssembly)); } } }
public void Configure(IExportRegistrationBlock registrationBlock) { registrationBlock.Export<BasicService>().As<IBasicService>(); }
public void Configure(IExportRegistrationBlock container) { bool enableLocalization = true; string absoluteFileName = HostingEnvironment.MapPath("~/Mvc.sitemap"); TimeSpan absoluteCacheExpiration = TimeSpan.FromMinutes(5); TimeSpan slidingCacheExpiration = TimeSpan.MinValue; bool includeRootNode = true; bool useNestedDynamicNodeRecursion = false; bool visibilityAffectsDescendants = true; bool useTitleIfDescriptionNotProvided = true; bool securityTrimmingEnabled = false; string[] includeAssembliesForScan = new string[] { "MvcSitemap2" }; var currentAssembly = this.GetType().Assembly; var siteMapProviderAssembly = typeof(SiteMaps).Assembly; var allAssemblies = new Assembly[] { currentAssembly, siteMapProviderAssembly }; var excludeTypes = new Type[] { // Use this array to add types you wish to explicitly exclude from convention-based // auto-registration. By default all types that either match I[TypeName] = [TypeName] or // I[TypeName] = [TypeName]Adapter will be automatically wired up as long as they don't // have the [ExcludeFromAutoRegistrationAttribute]. // // If you want to override a type that follows the convention, you should add the name // of either the implementation name or the interface that it inherits to this list and // add your manual registration code below. This will prevent duplicate registrations // of the types from occurring. // Example: // typeof(SiteMap), // typeof(SiteMapNodeVisibilityProviderStrategy) typeof(SiteMapNodeUrlResolver) }; var multipleImplementationTypes = new Type[] { typeof(ISiteMapNodeUrlResolver), typeof(ISiteMapNodeVisibilityProvider), typeof(IDynamicNodeProvider) }; // Matching type name (I[TypeName] = [TypeName]) or matching type name + suffix Adapter (I[TypeName] = [TypeName]Adapter) // and not decorated with the [ExcludeFromAutoRegistrationAttribute]. CommonConventions.RegisterDefaultConventions( (interfaceType, implementationType) => container.Export(implementationType).As(interfaceType).AndSingleton(), new Assembly[] { siteMapProviderAssembly }, allAssemblies, excludeTypes, string.Empty); // Multiple implementations of strategy based extension points (and not decorated with [ExcludeFromAutoRegistrationAttribute]). CommonConventions.RegisterAllImplementationsOfInterface( (interfaceType, implementationType) => container.Export(implementationType).As(interfaceType).AndSingleton(), multipleImplementationTypes, allAssemblies, new Type[0], string.Empty); // Registration of internal controllers CommonConventions.RegisterAllImplementationsOfInterface( (interfaceType, implementationType) => container.Export(implementationType).As(interfaceType).ExternallyOwned(), new Type[] { typeof(IController) }, new Assembly[] { siteMapProviderAssembly }, new Type[0], string.Empty); // Visibility Providers container.Export<SiteMapNodeVisibilityProviderStrategy>() .As<ISiteMapNodeVisibilityProviderStrategy>() .WithCtorParam(() => string.Empty).Named("defaultProviderName"); // Pass in the global controllerBuilder reference container.ExportInstance((scope, context) => ControllerBuilder.Current); container.Export<ControllerTypeResolverFactory>().As<IControllerTypeResolverFactory>() .WithCtorParam(() => new string[0]).Named("areaNamespacesToIgnore"); // Configure Security string attributeModuleKey = typeof(AuthorizeAttributeAclModule).Name; container.Export<AuthorizeAttributeAclModule>() .As<IAclModule>() .WithKey(attributeModuleKey); string xmlModuleKey = typeof(XmlRolesAclModule).Name; container.Export<XmlRolesAclModule>() .As<IAclModule>() .WithKey(xmlModuleKey); container.Export<CompositeAclModule>() .As<IAclModule>() .WithCtorParam<IAclModule[]>().Named("aclModules").LocateWithKey(new[] { attributeModuleKey, xmlModuleKey }); // Configure cache container.ExportInstance<System.Runtime.Caching.ObjectCache>( (scope, context) => System.Runtime.Caching.MemoryCache.Default); container.Export(typeof(RuntimeCacheProvider<>)).As(typeof(ICacheProvider<>)); container.Export<RuntimeFileCacheDependency>() .As<ICacheDependency>() .WithKey("cacheDependency1") .WithCtorParam(() => absoluteFileName).Named("fileName"); container.Export<CacheDetails>() .As<ICacheDetails>() .WithKey("cacheDetails1") .WithCtorParam<ICacheDependency>().LocateWithKey("cacheDependency1") .WithNamedCtorValue(() => absoluteCacheExpiration) .WithNamedCtorValue(() => slidingCacheExpiration); // Configure the visitors container.Export<UrlResolvingSiteMapNodeVisitor>().As<ISiteMapNodeVisitor>(); // Prepare for our node providers container.Export<FileXmlSource>() .As<IXmlSource>() .WithKey("xmlSource1") .WithCtorParam(() => absoluteFileName); container.Export<ReservedAttributeNameProvider>().As<IReservedAttributeNameProvider>() .WithCtorParam(() => new string[0]).Named("attributesToIgnore"); // Register the sitemap node providers container.Export<XmlSiteMapNodeProvider>() .As<ISiteMapNodeProvider>() .WithKey("xmlSiteMapNodeProvider1") .WithCtorParam<IXmlSource>().LocateWithKey("xmlSource1") .WithNamedCtorValue(() => includeRootNode) .WithNamedCtorValue(() => useNestedDynamicNodeRecursion); container.Export<ReflectionSiteMapNodeProvider>() .As<ISiteMapNodeProvider>() .WithKey("reflectionSiteMapNodeProvider1") .WithCtorParam(() => includeAssembliesForScan).Named("includeAssemblies") .WithCtorParam(() => new string[0]).Named("excludeAssemblies"); container.Export<CompositeSiteMapNodeProvider>() .As<ISiteMapNodeProvider>() .WithKey("siteMapNodeProvider1") .WithCtorParam<ISiteMapNodeProvider[]>().LocateWithKey(new[] { "xmlSiteMapNodeProvider1", "reflectionSiteMapNodeProvider1" }); // Register the sitemap builders container.Export<SiteMapBuilder>() .As<ISiteMapBuilder>() .WithKey("siteMapBuilder1") .WithCtorParam<ISiteMapNodeProvider>().Named("siteMapNodeProvider").LocateWithKey("siteMapNodeProvider1"); // Configure the builder sets container.Export<SiteMapBuilderSet>() .As<ISiteMapBuilderSet>() .WithKey("builderSet1") .WithCtorParam(() => "default").Named("instanceName") .WithCtorParam<ISiteMapBuilder>().Named("siteMapBuilder").LocateWithKey("siteMapBuilder1") .WithCtorParam<ICacheDetails>().Named("cacheDetails").LocateWithKey("cacheDetails1") .WithNamedCtorValue(() => securityTrimmingEnabled) .WithNamedCtorValue(() => enableLocalization) .WithNamedCtorValue(() => visibilityAffectsDescendants) .WithNamedCtorValue(() => useTitleIfDescriptionNotProvided); container.Export<SiteMapBuilderSetStrategy>() .As<ISiteMapBuilderSetStrategy>() .WithCtorParam<ISiteMapBuilderSet[]>().Named("siteMapBuilderSets").LocateWithKey(new[] { "builderSet1" }); }
private void ProcessDirecotry(IExportRegistrationBlock registrationBlock, AssemblyDirectoryElement assemblyDirectoryElement) { var assemblyFiles = Directory.GetFiles(assemblyDirectoryElement.Path, "*.dll"); foreach (string assemblyFile in assemblyFiles) { AssemblyName assemblyName = AssemblyName.GetAssemblyName(assemblyFile); Assembly newAssembly = Assembly.Load(assemblyName); if (assemblyDirectoryElement.ScanForAttributes) { registrationBlock.Export(Types.FromAssembly(newAssembly)); } else { ExportInterfaceElementCollection exportInterfaces = assemblyDirectoryElement.ExportInterfaces; if (exportInterfaces != null && exportInterfaces.Count > 0) { ProcessExportInterfaces(registrationBlock, exportInterfaces, Types.FromAssembly(newAssembly)); } } } }
private void ProcessExportElement(IExportRegistrationBlock registrationBlock, ExportElement exportElement) { Type exportType = ConvertStringToType(exportElement.Type); if (exportType != null) { IFluentExportStrategyConfiguration config = registrationBlock.Export(exportType); if (exportElement.ExternallyOwned) { config = config.ExternallyOwned(); } config.InEnvironment(exportElement.Environment); if (exportElement.AutoWireProperties) { config.AutoWireProperties(); } foreach (AsElement asElement in exportElement) { if (asElement.Type != null) { Type asType = ConvertStringToType(asElement.Type); if (asType != null) { config = config.As(asType); } } else if (asElement.Name != null) { config.AsName(asElement.Name); } } ILifestyle lifeStyle = ConvertStringToLifestyle(exportElement.LifeStyle); if (lifeStyle != null) { config.UsingLifestyle(lifeStyle); } } }
private void ProcessExportInterfaces(IExportRegistrationBlock registrationBlock, ExportInterfaceElementCollection exportInterfaces, IEnumerable<Type> exportTypes) { foreach (ExportInterfaceElement exportInterfaceElement in exportInterfaces) { Type interfaceType = ConvertStringToType(exportInterfaceElement.Type); ILifestyle lifestyle = ConvertStringToLifestyle(exportInterfaceElement.LifeStyle); var config = registrationBlock.Export(exportTypes). ByInterface(interfaceType); if (lifestyle != null) { config.UsingLifestyle(lifestyle); } if (exportInterfaceElement.ExternallyOwned) { config.ExternallyOwned(); } } }
private void SetupDispatchedMessenger(IExportRegistrationBlock registrationBlock) { registrationBlock.Export<DispatchedMessenger>(). As<IDispatchedMessenger>(). AndSingleton(); }
private void SetupValidation(IExportRegistrationBlock registrationBlock) { }
/// <summary> /// Extension to export a list of types to a registration block /// </summary> /// <param name="types">list of types</param> /// <param name="registrationBlock">registration block</param> /// <returns>configuration object</returns> public static IExportTypeSetConfiguration ExportTo(this IEnumerable<Type> types, IExportRegistrationBlock registrationBlock) { return registrationBlock.Export(types); }
public void Configure(IExportRegistrationBlock registrationBlock) { }