当前位置: 首页>>代码示例>>C#>>正文


C# ContainerBuilder.RegisterAdapter方法代码示例

本文整理汇总了C#中Autofac.ContainerBuilder.RegisterAdapter方法的典型用法代码示例。如果您正苦于以下问题:C# ContainerBuilder.RegisterAdapter方法的具体用法?C# ContainerBuilder.RegisterAdapter怎么用?C# ContainerBuilder.RegisterAdapter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Autofac.ContainerBuilder的用法示例。


在下文中一共展示了ContainerBuilder.RegisterAdapter方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Load

 protected override void Load(ContainerBuilder builder)
 {
     //將所有註冊在容器中的IProviderEntrance,放往MainAdapter
     //故將會轉換為IEnumerable<MainAdapter>
     builder.RegisterAdapter<IProviderEntrance, MainAdapter>(adp =>new MainAdapter(adp)).SingleInstance();
 }
开发者ID:toasttsao,项目名称:WEB_API_AutoFac_sample,代码行数:6,代码来源:moduleConfig.cs

示例2: Load

        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterAssemblyTypes(_assemblyWithInfrastructure).AsImplementedInterfaces();
            builder.RegisterAssemblyTypes(_assemblyWithInfrastructure).AsSelf();

            builder.RegisterType<ConfigureNHibernate>()
                .WithParameters(new[]
                                    {
                                        new NamedParameter("connectionString",
                                                           _connectionString),
                                        new NamedParameter("assembliesWithEntities",
                                                           new[] {typeof (Event).Assembly})
                                    })
                .SingleInstance();

            builder.RegisterAdapter<ConfigureNHibernate, NHibernate.Cfg.Configuration>(configure => configure.CreateConfiguration())
                .SingleInstance();

            builder.RegisterAdapter<NHibernate.Cfg.Configuration, ISessionFactory>(configuration => configuration.BuildSessionFactory())
                .SingleInstance();

            builder.RegisterType<SchemaUpdate>();

            // TODO: create transaction when opening, abort on error, commit on success
            builder.RegisterAdapter<ISessionFactory, ISession>(factory => TransactionPerRequest.SetSessionAndStartTransaction(factory.OpenSession()))
                .HttpRequestScoped();
                

            builder.RegisterGeneric(typeof(NHibernateRepository<>))
                .As(typeof(IRepository<>))
                .HttpRequestScoped();

            
        }
开发者ID:netponto,项目名称:NetPonto.Web,代码行数:34,代码来源:InfrastructureModule.cs

示例3: Load

        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterType<IO.PSCurrentWorkingDirectory>()
                .As<ICurrentWorkingDirectory>()
                .InstancePerLifetimeScope();

            builder.RegisterType<SessionState>()
                .AsSelf()
                .SingleInstance();

            builder.RegisterType<SessionStateWrapper>()
                .As<ISessionState>()
                .InstancePerLifetimeScope();

            // Retrieve the console background color
            builder.RegisterAdapter<ISessionState, ConsoleColor>((c, s) =>
            {
                const ConsoleColor DefaultBackground = ConsoleColor.DarkBlue;

                if (s.PSVariable == null)
                {
                    return DefaultBackground;
                }

                var host = s.PSVariable.GetValue("Host") as System.Management.Automation.Host.PSHost;

                if(host == null)
                {
                    return DefaultBackground;
                }

                return host.UI.RawUI.BackgroundColor;
            });

            builder.RegisterAdapter<ISessionState, IGitPromptSettings>((c, s) =>
            {
                var defaultSettings = c.Resolve<Settings.DefaultGitPromptSettings>();

                // If available, use from session information
                if (s.PSVariable != null)
                {
                    var psobject = s.PSVariable.GetValue("GitPromptSettings") as PSObject;

                    if (psobject != null)
                    {
                        return new PSObjectGitPromptSettings(psobject, defaultSettings);
                    }
                }

                // Otherwise, use default settings
                return defaultSettings;
            });
        }
开发者ID:automagic,项目名称:poshgit2,代码行数:53,代码来源:PSAutofacModule.cs

示例4: Load

        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterType<WebApplicationComponent>().InstancePerDependency();
            builder.RegisterType<EntityServiceComponent>().InstancePerDependency();

            builder.RegisterAdapter<IWebAppEndpoint, ILifecycleEventListener>(
                (context, endpoint) => context.Resolve<WebApplicationComponent>(TypedParameter.From(endpoint)));

            builder.RegisterAdapter<IDataRepositoryEndpoint, ILifecycleEventListener>(
                (context, endpoint) => context.Resolve<EntityServiceComponent>(TypedParameter.From(endpoint)));

            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
        }
开发者ID:votrongdao,项目名称:NWheels,代码行数:13,代码来源:ModuleLoader.cs

示例5: Load

        protected override void Load(ContainerBuilder builder)
        {
            base.Load(builder);

            builder.RegisterType<ImageLoader>()
                   .As<IImageLoader>()
                   .SingleInstance();

            builder.RegisterAdapter<ImageCodecInfo, ImageCodecAdapter>(c => new ImageCodecAdapter(c))
                   .As<IImageFormat>()
                   .SingleInstance();

            var codecs = ImageCodecInfo.GetImageEncoders();
            foreach (var codec in codecs) {
                builder.RegisterInstance(codec);
            }
        }
开发者ID:ashmind,项目名称:gallery,代码行数:17,代码来源:GdiImagingModule.cs

示例6: Load

        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterType<ExpiringCache>()
                .As<IRepositoryCache>()
                .SingleInstance();

            builder.RegisterType<UpdateableRepositoryStatus>()
                .As<IRepositoryStatus>();

            builder.RegisterType<LibGit2Sharp.Repository>()
                .As<LibGit2Sharp.IRepository>();

            builder.RegisterType<GitFolderWatcher>()
                .As<IFolderWatcher>();

            builder.RegisterType<Writers.ConsoleStatusWriter>()
                .As<IStatusWriter>()
                .InstancePerLifetimeScope();

            builder.RegisterType<Settings.DefaultGitPromptSettings>()
                .AsSelf()
                .InstancePerDependency();

            builder.Register(_ => new CancellationTokenSource(TimeOut))
                .AsSelf()
                .InstancePerDependency();

            builder.RegisterAdapter<CancellationTokenSource, CancellationToken>(s => s.Token);

            builder.Register(c =>
                {
                    var cache = c.Resolve<IRepositoryCache>();
                    var cwd = c.Resolve<ICurrentWorkingDirectory>();
                    var cancellationToken = c.Resolve<CancellationToken>();

                    return cache.FindRepoAsync(cwd, cancellationToken);
                })
                .As<Task<IRepositoryStatus>>()
                .InstancePerLifetimeScope();
        }
开发者ID:automagic,项目名称:poshgit2,代码行数:40,代码来源:PoshGitAutofacModule.cs

示例7: Build

        public static IContainer Build(ICommandLineOptions options, ProductInformation productInformation)
        {
            var builder = new ContainerBuilder();

            builder.RegisterType<TargetMapper>()
                .As<ITargetMapper>()
                .OnActivated(c => c.Instance.LoadFromConfig(options.TargetMapFile))
                .SingleInstance();

            builder.RegisterInstance<ICommandLineOptions>(options);

#if DEBUG_SERVICE
            // For debug purposes, the FileOutputApiPortService helps as it serializes the request to json and opens it with the
            // default json handler. To use this service, uncomment the the next line and comment the one after that.
            container.RegisterType<FileOutputApiPortService>()
                .As<IApiPortService>()
                .SingleInstance();
#else
            builder.RegisterInstance<IApiPortService>(new ApiPortService(options.ServiceEndpoint, productInformation));
#endif

            builder.RegisterType<FileIgnoreAssemblyInfoList>()
                .As<IEnumerable<IgnoreAssemblyInfo>>()
                .SingleInstance();

            builder.RegisterType<ReflectionMetadataDependencyFinder>()
                .As<IDependencyFinder>()
                .SingleInstance();

            builder.RegisterType<DotNetFrameworkFilter>()
                .As<IDependencyFilter>()
                .SingleInstance();

            builder.RegisterType<ReportGenerator>()
                .As<IReportGenerator>()
                .SingleInstance();

            builder.RegisterType<ApiPortClient>()
                .SingleInstance();

            builder.RegisterType<ApiPortService>()
                .SingleInstance();

            builder.RegisterType<WindowsFileSystem>()
                .As<IFileSystem>()
                .SingleInstance();

            builder.RegisterType<ReportFileWriter>()
                .As<IFileWriter>()
                .SingleInstance();

            builder.RegisterType<RequestAnalyzer>()
                .As<IRequestAnalyzer>()
                .SingleInstance();

            builder.RegisterType<AnalysisEngine>()
                .As<IAnalysisEngine>()
                .SingleInstance();

            builder.RegisterType<ConsoleApiPort>()
                .SingleInstance();

            builder.RegisterAdapter<ICommandLineOptions, IApiPortOptions>((ctx, opts) =>
            {
                if (opts.OutputFormats?.Any() == true)
                {
                    return opts;
                }

                return new ReadWriteApiPortOptions(opts)
                {
                    OutputFormats = new[] { ctx.ResolveNamed<string>(DefaultOutputFormatInstanceName) }
                };
            })
            .SingleInstance();

            builder.RegisterType<DocIdSearchRepl>();

            builder.RegisterType<ApiPortServiceSearcher>()
                .As<ISearcher<string>>()
                .SingleInstance();

            // Register the default output format name
            builder.RegisterInstance("Excel")
                .Named<string>(DefaultOutputFormatInstanceName);

            if (Console.IsOutputRedirected)
            {
                builder.RegisterInstance<IProgressReporter>(new TextWriterProgressReporter(Console.Out));
            }
            else
            {
                builder.RegisterType<ConsoleProgressReporter>()
                    .As<IProgressReporter>()
                    .SingleInstance();
            }

            TryLoadOffline(builder);

            return builder.Build();
//.........这里部分代码省略.........
开发者ID:AlexGhiondea,项目名称:dotnet-apiport,代码行数:101,代码来源:DependencyBuilder.cs

示例8: Load

 protected override void Load(ContainerBuilder builder) {
     builder.RegisterAdapter<IFieldTypeEditor, IConcreteFieldTypeEditor>(editor => new FieldTypeEditorAdaptor(editor));
 }
开发者ID:wezmag,项目名称:Coevery,代码行数:3,代码来源:FieldTypeEditorModule.cs

示例9: ServiceProvider

        public ServiceProvider(ApiPortVSPackage serviceProvider)
        {
            var builder = new ContainerBuilder();

            // VS type registration
            builder.RegisterType<ErrorListProvider>()
                .AsSelf()
                .SingleInstance();
            builder.RegisterInstance(serviceProvider)
                .As<IResultToolbar>()
                .As<IServiceProvider>();
            builder.Register(_ => Package.GetGlobalService(typeof(SVsWebBrowsingService)))
                .As<IVsWebBrowsingService>();
            builder.RegisterType<VsBrowserReportViewer>()
                .As<IReportViewer>()
                .SingleInstance();
            builder.RegisterType<ToolbarListReportViewer>()
                .As<IReportViewer>()
                .InstancePerLifetimeScope();
            builder.RegisterType<ApiPortVsAnalyzer>()
                .As<IVsApiPortAnalyzer>()
                .InstancePerLifetimeScope();
            builder.Register(_ => Package.GetGlobalService(typeof(SVsSolutionBuildManager)))
                .As<IVsSolutionBuildManager2>();
            builder.RegisterType<ProjectBuilder>()
                .AsSelf();

            // Service registration
            builder.RegisterInstance(new ProductInformation("ApiPort_VS"))
                .AsSelf();
            builder.RegisterType<ApiPortService>().
                As<IApiPortService>().
                WithParameter(TypedParameter.From<string>(DefaultEndpoint))
                .SingleInstance();
            builder.RegisterType<ApiPortClient>()
                .AsSelf()
                .SingleInstance();
            builder.Register(_ => OptionsModel.Load())
                .As<OptionsModel>()
                .OnRelease(m => m.Save())
                .SingleInstance();
            builder.RegisterType<TargetMapper>()
                .As<ITargetMapper>()
                .OnActivated(h => h.Instance.LoadFromConfig())
                .InstancePerLifetimeScope();
            builder.RegisterType<WindowsFileSystem>()
                .As<IFileSystem>()
                .SingleInstance();

            // Register output services
            builder.RegisterType<ReportGenerator>()
                .As<IReportGenerator>()
                .SingleInstance();
            builder.RegisterType<OutputWindowWriter>()
                .AsSelf()
                .As<TextWriter>()
                .SingleInstance();
            builder.RegisterType<TextWriterProgressReporter>()
                .As<IProgressReporter>()
                .SingleInstance();
            builder.RegisterType<ReportFileWriter>()
                .As<IFileWriter>()
                .SingleInstance();
            builder.RegisterAdapter<IServiceProvider, DTE>(provider => (DTE)provider.GetService(typeof(DTE)));

            builder.RegisterAdapter<IServiceProvider, IVsOutputWindowPane>(provider =>
            {
                var outputWindow = provider.GetService(typeof(SVsOutputWindow)) as IVsOutputWindow;

                IVsOutputWindowPane windowPane;
                if (outputWindow.GetPane(ref OutputWindowGuid, out windowPane) == S_OK)
                {
                    return windowPane;
                }

                if (outputWindow.CreatePane(ref OutputWindowGuid, LocalizedStrings.PortabilityOutputTitle, 1, 0) == S_OK)
                {
                    if (outputWindow.GetPane(ref OutputWindowGuid, out windowPane) == S_OK)
                    {
                        return windowPane;
                    }
                }

                // If a custom window couldn't be opened, open the general purpose window
                return provider.GetService(typeof(SVsGeneralOutputWindowPane)) as IVsOutputWindowPane;
            }).SingleInstance();
            builder.RegisterInstance(AnalysisOutputToolWindowControl.Model)
                .As<OutputViewModel>()
                .SingleInstance();

            // Register menu handlers
            builder.RegisterType<AnalyzeMenu>()
                .AsSelf()
                .SingleInstance();
            builder.RegisterType<FileListAnalyzer>()
                .AsSelf()
                .InstancePerLifetimeScope();
            builder.RegisterType<ProjectAnalyzer>()
                .AsSelf()
                .InstancePerLifetimeScope();
//.........这里部分代码省略.........
开发者ID:AlexGhiondea,项目名称:dotnet-apiport,代码行数:101,代码来源:ServiceProvider.cs


注:本文中的Autofac.ContainerBuilder.RegisterAdapter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。