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}."); } }
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 block) { block.Export <PhoneModelInfoInfoReader>().As <IPhoneModelInfoReader>(); block.Export <PhoneInfoReader>().As <IPhoneInfoReader>(); block.Export <LumiaContextualizer>().As <IContextualizer>(); //block.Export<LumiaDetector>().As<IDetector>(); }
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); }
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 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(); block.ExportFactory((IDownloader downloader) => new XmlDeviceRepository(new Uri("https://raw.githubusercontent.com/WOA-Project/Deployment-Feed/master/Deployments.xml"), downloader)) .As <IDeviceRepository>().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>(); } }
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 void Configure(IExportRegistrationBlock registrationBlock) { registrationBlock.Export(AllTypes()) .BasedOn <IController>() .ByType() .ExternallyOwned(); }
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(AllTypes()) .BasedOn<IController>() .ByType() .ExternallyOwned(); }
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(); }
/// <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 c) { c.ExportInstance(serviceLocator).Lifestyle.Singleton(); c.Export <EventAggregator>().As <IEventAggregator>().Lifestyle.Singleton(); c.Export <TreeNodeView>().As <ITreeNodeView>(); c.Export <RuleFactory>().As <IRuleFactory>(); c.Export <RuleEditView>().As <IRuleEditView>().Lifestyle.Singleton(); c.Export <MessageBoxService>().As <IMessageBoxService>().Lifestyle.Singleton(); c.Export <RulePreviewView>().As <IRulePreviewView>().Lifestyle.Singleton(); c.Export <RulesTreeView>().As <IRulesTreeView>().Lifestyle.Singleton(); c.Export <RuleExecutorFactory>().As <IRuleExecutorFactory>().Lifestyle.Singleton(); }
public static IExportRegistrationBlock ExportForAllTenants(this IExportRegistrationBlock config, IEnumerable <ITenant> tenants, Type interfaceType, Type implementationType, Action <IFluentExportStrategyConfiguration> configure = null) { foreach (var tenant in tenants) { var exportConfig = config.Export(implementationType).AsKeyed(interfaceType, tenant.Key); configure?.Invoke(exportConfig); } config.ExportPerTenantFactory(interfaceType); return(config); }
private static void Register(IExportRegistrationBlock c, IEnumerable <DependentRegistration> descriptors) { foreach (var descriptor in descriptors) { if (descriptor.Implementation != null) { c.Export(descriptor.Implementation). As(descriptor.Registration.ServiceType). ConfigureLifetime(descriptor.Registration.Lifecycle); } } }
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)); }
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>(); }
public void Configure(IExportRegistrationBlock block) { block.Export <GuiRequirementSatisfier>().As <IRequirementSatisfier>().Lifestyle.Singleton(); block.Export <WpfDialogService>().As <IDialogService>().Lifestyle.Singleton(); block.Export <SettingsService>().As <ISettingsService>().Lifestyle.Singleton(); block.Export <OpenFilePicker>().As <IOpenFilePicker>().Lifestyle.Singleton(); block.Export <DesktopFilePicker>().As <IFilePicker>().Lifestyle.Singleton(); block.ExportFactory <Uri, IFileSystemOperations, ZafiroFile>((uri, f) => new DesktopZafiroFile(uri, f, null)); block.Export <MarkdownService>().As <IMarkdownService>().Lifestyle.Singleton(); var simpleInteraction = new SimpleInteraction(); simpleInteraction.Register("Requirements", typeof(Requirements)); block.ExportInstance(simpleInteraction).As <ISimpleInteraction>(); block.Export <WoaDeployer>().Lifestyle.Singleton(); }
// todo: move to Grace? (and remove his from private) public static void PopulateFrom(this IExportRegistrationBlock exportConfig, IEnumerable <ServiceDescriptor> descriptors) { foreach (var descriptor in descriptors) { if ((object)descriptor.ImplementationType != null) { exportConfig.Export(descriptor.ImplementationType).As(descriptor.ServiceType).ConfigureLifetime(descriptor.Lifetime); } else if (descriptor.ImplementationFactory != null) { exportConfig.ExportFactory(descriptor.ImplementationFactory).As(descriptor.ServiceType).ConfigureLifetime(descriptor.Lifetime); } else { exportConfig.ExportInstance(descriptor.ImplementationInstance).As(descriptor.ServiceType).ConfigureLifetime(descriptor.Lifetime); } } }
private static void RegisterPerTenant(IExportRegistrationBlock exportConfig, IEnumerable <ServiceDescriptor> descriptors, TTenant tenant) { foreach (var descriptor in descriptors) { if ((object)descriptor.ImplementationType != null) { exportConfig.Export(descriptor.ImplementationType).AsKeyed(descriptor.ServiceType, tenant.Key).ConfigureLifetime(descriptor.Lifetime); } else if (descriptor.ImplementationFactory != null) { exportConfig.ExportFactory(descriptor.ImplementationFactory).AsKeyed(descriptor.ServiceType, tenant.Key).ConfigureLifetime(descriptor.Lifetime); } else { exportConfig.ExportInstance(descriptor.ImplementationInstance).AsKeyed(descriptor.ServiceType, tenant.Key).ConfigureLifetime(descriptor.Lifetime); } exportConfig.ExportPerTenantFactory(descriptor.ServiceType); } }
public void Configure(IExportRegistrationBlock builder) { builder.Export <Mediator>() .As <IMediator>() .Lifestyle.Singleton(); var mediatrOpenTypes = new[] { typeof(IRequestHandler <,>), typeof(IRequestPostProcessor <,>) }; foreach (var mediatrOpenType in mediatrOpenTypes) { builder.ExportAssemblyContaining <GithubAuthentication>() .ByInterface(mediatrOpenType); } builder.ExportInstance <ServiceFactory>((scope, context) => scope.Locate); }
public void Configure(IExportRegistrationBlock block) { block.Export <GuiRequirementSatisfier>().As <IRequirementSatisfier>().Lifestyle.Singleton(); block.Export <WpfDialogService>().As <IDialogService>().Lifestyle.Singleton(); block.Export <SettingsService>().As <ISettingsService>().Lifestyle.Singleton(); block.Export <OpenFilePicker>().As <IOpenFilePicker>().Lifestyle.Singleton(); block.Export <DesktopFilePicker>().As <IFilePicker>().Lifestyle.Singleton(); block.ExportFactory <Uri, IFileSystemOperations, ZafiroFile>((uri, f) => new DesktopZafiroFile(uri, f, null)); block.Export <MarkdownService>().As <IMarkdownService>().Lifestyle.Singleton(); var simpleInteraction = new SimpleInteraction(); simpleInteraction.Register("Requirements", typeof(Requirements)); block.ExportInstance(simpleInteraction).As <ISimpleInteraction>(); block.Export <ScriptDeployer>().As <Core.Deployer>().Lifestyle.Singleton(); block.Export <DeviceDeployer>().As <Core.Deployer>().Lifestyle.Singleton(); block.ExportAssemblies(Assemblies.AppDomainAssemblies) .Where(y => typeof(ISection).IsAssignableFrom(y)) .ByInterface <ISection>() .ByInterface <IBusy>() .ByType() .ExportAttributedTypes() .Lifestyle.Singleton(); }
private static void Register(IExportRegistrationBlock c, IEnumerable <ServiceDescriptor> descriptors) { foreach (var descriptor in descriptors) { if (descriptor.ImplementationType != null) { c.Export(descriptor.ImplementationType). As(descriptor.ServiceType). ConfigureLifetime(descriptor.Lifetime); } else if (descriptor.ImplementationFactory != null) { c.ExportInstance((scope, context) => descriptor.ImplementationFactory(new GraceServiceProvider(scope))). As(descriptor.ServiceType). ConfigureLifetime(descriptor.Lifetime); } else { c.ExportInstance(descriptor.ImplementationInstance). As(descriptor.ServiceType). ConfigureLifetime(descriptor.Lifetime); } } }
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; #if Demo // Settings for MvcMusicStore demo: don't copy into your project bool securityTrimmingEnabled = true; string[] includeAssembliesForScan = new string[] { "Mvc Music Store" }; #else bool securityTrimmingEnabled = false; string[] includeAssembliesForScan = new string[] { "$AssemblyName$" }; #endif 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" }); }
public void Configure(IExportRegistrationBlock registrationBlock) { registrationBlock.Export <BasicService>().As <IBasicService>(); }
public static void ExportDefault(this IExportRegistrationBlock e, Type type) { e.Export(type).ByInterfaces().As(type).Lifestyle.Singleton(); }
private void SetupDispatchedMessenger(IExportRegistrationBlock registrationBlock) { registrationBlock.Export<DispatchedMessenger>(). As<IDispatchedMessenger>(). AndSingleton(); }
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>(); registrationBlock.ExportInstance(IntProperty).AsName("IntProperty"); }
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" }); }
/// <summary> /// Export a particular type as a particular interface /// </summary> /// <typeparam name="T">Type to export</typeparam> /// <typeparam name="TInterface">type to export as</typeparam> /// <param name="registrationBlock"></param> /// <returns></returns> public static IFluentExportStrategyConfiguration <T> ExportAs <T, TInterface>(this IExportRegistrationBlock registrationBlock) where T : TInterface { return(registrationBlock.Export <T>().As <TInterface>()); }
/// <summary> /// Export all types from an assembly comtaining a specific type /// </summary> /// <typeparam name="T"></typeparam> /// <param name="registrationBlock"></param> /// <returns></returns> public static IExportTypeSetConfiguration ExportAssemblyContaining <T>(this IExportRegistrationBlock registrationBlock) { return(registrationBlock.Export(typeof(T).GetTypeInfo().Assembly.ExportedTypes)); }
public void Configure(IExportRegistrationBlock registrationBlock) { registrationBlock.Export<BasicService>().As<IBasicService>(); }
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(); } } }
/// <summary> /// Export types from an assembly /// </summary> /// <param name="registrationBlock"></param> /// <param name="assembly"></param> /// <returns></returns> public static IExportTypeSetConfiguration ExportAssembly(this IExportRegistrationBlock registrationBlock, Assembly assembly) { return(registrationBlock.Export(assembly.ExportedTypes)); }
public void Configure(IExportRegistrationBlock block) { block.Export <FileSystem>().As <IFileSystem>().Lifestyle.Singleton(); block.Export <ImageFlasher>().As <IImageFlasher>().Lifestyle.Singleton(); block.Export <DismImageService>().As <IWindowsImageService>().Lifestyle.Singleton(); }
public void Configure(IExportRegistrationBlock block) { block.Export <OperationContext>().As <IOperationContext>().Lifestyle.SingletonPerScope(); block.Export <OperationProgress>().As <IOperationProgress>().Lifestyle.SingletonPerScope(); }
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)); } } } }
/// <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)); }
/// <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); }