本文整理汇总了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();
}
示例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();
}
示例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;
});
}
示例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());
}
示例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);
}
}
示例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();
}
示例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();
//.........这里部分代码省略.........
示例8: Load
protected override void Load(ContainerBuilder builder) {
builder.RegisterAdapter<IFieldTypeEditor, IConcreteFieldTypeEditor>(editor => new FieldTypeEditorAdaptor(editor));
}
示例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();
//.........这里部分代码省略.........