public IEnumerable <IToken> Apply(IMutableContainer container) { // View Models yield return(container .Bind <IClockViewModel>().As(Singleton).To <ClockViewModel>()); // Models yield return(container .Bind <ITimer>().As(Singleton).To <Timer>(ctx => new Timer(TimeSpan.FromSeconds(1))) .Bind <IClock>().As(Singleton).To <Clock>()); }
public IEnumerable <IToken> Apply([NotNull] IMutableContainer container) { var setting = AWSSettings.Instance; yield return(container .Bind <ICommandHandler <SendMessageCommand> >() .Bind <ICommandHandler <DeleteMessageCommand> >() .Bind <IQueryHandler <ReceiveMessageQuery, IEnumerable <Message> > >() .To <AwsHandler>(ctx => new AwsHandler(setting.SQSConfig))); yield return(container .Bind <IMessageSender>().To <MessageSender>() .Bind <IMessageReceiver>().To <MessageReceiver>()); }
public IEnumerable <IToken> Apply(IMutableContainer container) { var value = 0; // Define a function to get sequential integer value Func <int> generator = () => Interlocked.Increment(ref value); // Bind this function using the corresponding tag 'Sequential' yield return(container.Bind <int>().Tag(GeneratorType.Sequential).To(ctx => generator())); var random = new Random(); // Define a function to get random integer value Func <int> randomizer = () => random.Next(); // Bind this function using the corresponding tag 'Random' yield return(container.Bind <int>().Tag(GeneratorType.Random).To(ctx => randomizer())); }
public void BindAndUnbind() { for (var i = 0; i < 1000; i++) { _container.Bind <IService3>().To <Service3>().Dispose(); } }
/// <inheritdoc /> public IEnumerable <IToken> Apply(IMutableContainer container) { if (container == null) { throw new ArgumentNullException(nameof(container)); } yield return(container.Bind <InterceptorBuilder, IInterceptorRegistry, IBuilder>().As(Lifetime.Singleton).To()); }
public IEnumerable <IToken> Apply(IMutableContainer container) { // Let's suppose that the initial message ID is 33 var id = 33; yield return(container // id generator .Bind <int>().To(ctx => Interlocked.Increment(ref id)) // abstract messenger .Bind(typeof(IInstantMessenger <>)).To(typeof(InstantMessenger <>)) // abstract subject .Bind <ISubject <TT> >().To <Subject <TT> >() // message factory .Bind <IMessageFactory <IMessage> >().To <Message>()); }
public IEnumerable <IToken> Apply(IMutableContainer container) { yield return(container .Bind <IMessageHandler>().To <MessageHandler>() .Bind <IOptions>().As(Singleton).To <Options>() .Bind <ITestCaseFilter>().To <TestCaseFilter>() .Bind <ISuiteNameProvider>().As(Singleton).To <SuiteNameProvider>() .Bind <ITeamCityServiceMessages>().To <TeamCityServiceMessages>() .Bind <IServiceMessageFormatter>().To <ServiceMessageFormatter>() .Bind <IFlowIdGenerator>().To <FlowIdGenerator>() .Bind <IIdGenerator>().To <IdGenerator>() .Bind <DateTime>().To(ctx => DateTime.Now) .Bind <IServiceMessageUpdater>().To <TimestampUpdater>() .Bind <IAttachments>().As(Singleton).To <Attachments>() .Bind <ITeamCityWriter>().To(ctx => ctx.Container.Inject <ITeamCityServiceMessages>().CreateWriter(Console.WriteLine))); }
public IEnumerable <IToken> Apply(IMutableContainer container) { if (container == null) { throw new ArgumentNullException(nameof(container)); } yield return(container .Bind <CancellationTokenSource>().As(Singleton).To <CancellationTokenSource>() .Bind <IFileSystem>().As(Singleton).To <FileSystem>() .Bind <IEnvironment>().As(Singleton).To <Environment>() .Bind <ILogger>().As(Singleton).Tag("Console").To <ConsoleLogger>() .Bind <ILogger>().As(Singleton).Tag("TeamCity").To <TeamCityLogger>() .Bind <ILogger>().As(Singleton).To <Logger>(ctx => new Logger( ctx.Container.Inject <IOptions>(), ctx.Container.Inject <IEnvironment>(), ctx.Container.Inject <ILogger>("Console"), ctx.Container.Inject <ILogger>("TeamCity"))) .Bind <IDockerClientFactory>().As(Singleton).To <DockerClientFactory>() .Bind <IDockerClient>().To(ctx => ctx.Container.Inject <IDockerClientFactory>().Create().Result) .Bind <IStreamService>().As(Singleton).To <StreamService>() .Bind <IMessageLogger>().As(Singleton).To <MessageLogger>() .Bind <IDockerConverter>().As(Singleton).To <DockerConverter>() .Bind <IPathService>().As(Singleton).To <PathService>() .Bind <IConfigurationExplorer>().As(Singleton).To <ConfigurationExplorer>() .Bind <IContentParser>().As(Singleton).To <ContentParser>() .Bind <IFactory <IEnumerable <IGraph <IArtifact, Dependency> >, IGraph <IArtifact, Dependency> > >().As(Singleton).To <BuildGraphsFactory>() .Bind <IScriptGenerator>().As(Singleton).To <ScriptGenerator>() .Bind <IGenerator>().Tag("Readme files").As(Singleton).To <ReadmeFilesGenerator>() .Bind <IGenerator>().Tag("Kotlin DSL").As(Singleton).To <TeamCityKotlinSettingsGenerator>() .Bind <IGenerator>().Tag("Scripts").As(Singleton).To <ScriptsGenerator>() .Bind <IFactory <IGraph <IArtifact, Dependency>, IEnumerable <Template> > >().As(Singleton).To <DockerGraphFactory>() .Bind <IContextFactory>().As(Singleton).To <ContextFactory>() .Bind <IBuildPathProvider>().As(Singleton).To <BuildPathProvider>() .Bind <IFactory <NodesDescription, IEnumerable <INode <IArtifact> > > >().As(Singleton).To <NodesNameFactory>() // TeamCity messages .Bind <IServiceMessageFormatter>().As(Singleton).To <ServiceMessageFormatter>() .Bind <IFlowIdGenerator>().As(Singleton).To <FlowIdGenerator>() .Bind <IServiceMessageUpdater>().As(Singleton).To(ctx => new TimestampUpdater(() => DateTime.Now)) .Bind <ITeamCityServiceMessages>().As(Singleton).To <TeamCityServiceMessages>() .Bind <ITeamCityWriter, ITeamCityMessageWriter>().As(Singleton).To(ctx => ctx.Container.Inject <ITeamCityServiceMessages>().CreateWriter()) .Bind <ICommand <IGenerateOptions> >().As(Singleton).To <GenerateCommand>() .Bind <ICommand <IBuildOptions> >().As(Singleton).To <BuildCommand>()); }
public IEnumerable <IToken> Apply(IMutableContainer container) { yield return(container .Bind <Page>().As(Singleton).To <MainPage>()); }
public IEnumerable <IToken> Apply(IMutableContainer container) { yield return(container.Bind <Service, IService>().To <Service>()); }
public IEnumerable <IToken> Apply(IMutableContainer container) { if (container == null) { throw new ArgumentNullException(nameof(container)); } yield return(container .Bind <INodeLogger>().As(Singleton).To <NodeLogger>() .Bind <IEnvironment>().As(Singleton).To <Environment>() .Bind <IDiagnostics>().As(Singleton).To <Diagnostics>() .Bind <ILoggerContext>().As(Singleton).To <LoggerContext>() .Bind <IConsole>().As(Singleton).To <DefaultConsole>() .Bind <IStringService>().As(Singleton).To <StringService>() .Bind <IPathService>().As(Singleton).To <PathService>() .Bind <IParametersParser>().As(Singleton).To <ParametersParser>() .Bind <IPerformanceCounterFactory>().As(Singleton).To <PerformanceCounterFactory>() .Bind <ILogFormatter>().As(Singleton).To <LogFormatter>() .Bind <IEventFormatter>().As(Singleton).To <EventFormatter>() .Bind <IBuildEventManager>().As(Singleton).To <BuildEventManager>() .Bind <IDeferredMessageWriter>().As(Singleton).To <DeferredMessageWriter>() .Bind <IMessageWriter>().As(Singleton).To <MessageWriter>() // Colors .Bind <IColorTheme>().As(Singleton).To <ColorTheme>( ctx => new ColorTheme(ctx.Container.Inject <ILoggerContext>(), ctx.Container.Inject <IColorTheme>(ColorThemeMode.Default), ctx.Container.Inject <IColorTheme>(ColorThemeMode.TeamCity))) .Bind <IColorTheme>().Tag(ColorThemeMode.Default).As(Singleton).To <DefaultColorTheme>() .Bind <IColorTheme>().Tag(ColorThemeMode.TeamCity).As(Singleton).To <TeamCityColorTheme>( ctx => new TeamCityColorTheme(ctx.Container.Inject <IColorTheme>(ColorThemeMode.Default))) // IStatistics .Bind <IStatistics>().As(Singleton).To <Statistics>( ctx => new Statistics(ctx.Container.Inject <ILoggerContext>(), ctx.Container.Inject <IStatistics>(StatisticsMode.Default), ctx.Container.Inject <IStatistics>(StatisticsMode.TeamCity))) .Bind <IStatistics>().Tag(StatisticsMode.Default).As(Singleton).To <DefaultStatistics>() .Bind <IStatistics>().Tag(StatisticsMode.TeamCity).As(Singleton).To <TeamCityStatistics>() // ILogWriter .Bind <ILogWriter>().As(Singleton).To <LogWriter>( ctx => new LogWriter(ctx.Container.Inject <ILoggerContext>(), ctx.Container.Inject <ILogWriter>(ColorMode.Default), ctx.Container.Inject <ILogWriter>(ColorMode.TeamCity), ctx.Container.Inject <ILogWriter>(ColorMode.NoColor), ctx.Container.Inject <ILogWriter>(ColorMode.AnsiColor))) .Bind <ILogWriter>().Tag(ColorMode.Default).As(Singleton).To <DefaultLogWriter>() .Bind <TeamCityHierarchicalMessageWriter, ILogWriter, IHierarchicalMessageWriter>().As(Singleton).Tag(ColorMode.TeamCity).Tag(TeamCityMode.SupportHierarchy).To() .Bind <ILogWriter>().Tag(ColorMode.NoColor).As(Singleton).To <NoColorLogWriter>() .Bind <ILogWriter>().Tag(ColorMode.AnsiColor).As(Singleton).To <AnsiLogWriter>() // IHierarchicalMessageWriter .Bind <IHierarchicalMessageWriter>().As(Singleton).To <HierarchicalMessageWriter>( ctx => new HierarchicalMessageWriter( ctx.Container.Inject <ILoggerContext>(), ctx.Container.Inject <IHierarchicalMessageWriter>(TeamCityMode.Off), ctx.Container.Inject <IHierarchicalMessageWriter>(TeamCityMode.SupportHierarchy))) .Bind <IHierarchicalMessageWriter>().Tag(TeamCityMode.Off).As(Singleton).To <DefaultHierarchicalMessageWriter>() // Build event handlers .Bind <IBuildEventHandler <BuildFinishedEventArgs> >().As(Singleton).To <BuildFinishedHandler>() .Bind <IBuildEventHandler <BuildStartedEventArgs> >().As(Singleton).To <BuildStartedHandler>() .Bind <IBuildEventHandler <CustomBuildEventArgs> >().As(Singleton).To <CustomEventHandler>() .Bind <IBuildEventHandler <BuildErrorEventArgs> >().As(Singleton).To <ErrorHandler>() .Bind <IBuildEventHandler <BuildMessageEventArgs> >().As(Singleton).To <MessageHandler>() .Bind <IBuildEventHandler <ProjectFinishedEventArgs> >().As(Singleton).To <ProjectFinishedHandler>() .Bind <IBuildEventHandler <ProjectStartedEventArgs> >().As(Singleton).To <ProjectStartedHandler>() .Bind <IBuildEventHandler <TargetFinishedEventArgs> >().As(Singleton).To <TargetFinishedHandler>() .Bind <IBuildEventHandler <TargetStartedEventArgs> >().As(Singleton).To <TargetStartedHandler>() .Bind <IBuildEventHandler <TaskFinishedEventArgs> >().As(Singleton).To <TaskFinishedHandler>() .Bind <IBuildEventHandler <TaskStartedEventArgs> >().As(Singleton).To <TaskStartedHandler>() .Bind <IBuildEventHandler <BuildWarningEventArgs> >().As(Singleton).To <WarningHandler>() // TeamCity messages .Bind <ITeamCityWriter>().To( ctx => CreateWriter(ctx.Container.Inject <ILogWriter>(ColorMode.NoColor))) .Bind <IServiceMessageParser>().As(Singleton).To <ServiceMessageParser>() .Bind <IPerformanceCounter>().To <PerformanceCounter>( ctx => new PerformanceCounter((string)ctx.Args[0], ctx.Container.Inject <ILogWriter>(), ctx.Container.Inject <IPerformanceCounterFactory>(), ctx.Container.Inject <IMessageWriter>())) .Bind <IColorStorage>().To <ColorStorage>()); }
public IEnumerable <IToken> Apply(IMutableContainer container) { // Design time View Models yield return(container .Bind <IClockViewModel>().To <ClockViewModelDesignTime>()); }
public IEnumerable <IToken> Apply(IMutableContainer container) { yield return(container .Bind <IDispatcher>().As(Singleton).To <Dispatcher>() .Bind <IMainWindowView>().As(Singleton).To <MainWindow>()); }
public void BindAndUnbind() => _container.Bind <IService3>().To <Service3>().Dispose();
/// <inheritdoc /> public IEnumerable <IToken> Apply(IMutableContainer container) { yield return(container.Bind <ICannotResolveDependency>().Bind <ICannotGetResolver>().To(ctx => this)); }
/// <inheritdoc /> public IEnumerable <IToken> Apply(IMutableContainer container) { if (container == null) { throw new ArgumentNullException(nameof(container)); } var singletonLifetimeResolver = container.GetResolver <ILifetime>(Lifetime.Singleton.AsTag()); var containerSingletonLifetimeResolver = container.GetResolver <ILifetime>(Lifetime.ContainerSingleton.AsTag()); var disposingLifetimeResolver = container.GetResolver <ILifetime>(Lifetime.Disposing.AsTag()); foreach (var serviceGroup in this.Reverse().Select((service, index) => new { index, item = service }).GroupBy(i => i.item.ServiceType)) { var isFirst = true; foreach (var description in serviceGroup) { var service = description.item; var binding = container.Bind(service.ServiceType); if (!isFirst) { binding = binding.Tag(description.index); } else { isFirst = false; } switch (service.Lifetime) { case ServiceLifetime.Transient: binding = binding.Lifetime(disposingLifetimeResolver(container)); break; case ServiceLifetime.Singleton: binding = binding.Lifetime(singletonLifetimeResolver(container)); break; case ServiceLifetime.Scoped: binding = binding.Lifetime(containerSingletonLifetimeResolver(container)); break; default: throw new NotSupportedException($"Unknown lifetime {service.Lifetime}."); } if (service.ImplementationType != null) { yield return(binding.To(service.ImplementationType)); continue; } if (service.ImplementationFactory != null) { yield return(binding.To(ctx => service.ImplementationFactory(ctx.Container.Inject <IServiceProvider>()))); continue; } if (service.ImplementationInstance != null) { yield return(binding.To(ctx => service.ImplementationInstance)); continue; } throw new NotSupportedException($"The service descriptor {service} is not supported."); } } yield return(container .Bind <IServiceProvider>().Bind <ISupportRequiredService>().Lifetime(singletonLifetimeResolver(container)).To <ServiceProvider>() .Bind <IServiceScopeFactory>().Lifetime(singletonLifetimeResolver(container)).To <ServiceScopeFactory>() .Bind <IServiceScope>().To <ServiceScope>() // IEnumerable should preserve an order .Bind <IEnumerable <TT> >().To(ctx => ctx.Container.Inject <IEnumerable <TT> >(TagKeyComparer.Shared, ctx.Args))); }
public IEnumerable <IToken> Apply(IMutableContainer container) { var autowiringStrategy = AutowiringStrategies .AspectOriented() .Tag <TagAttribute>(i => i.Tag); yield return(container .Bind <IAutowiringStrategy>().To(ctx => autowiringStrategy) // Settings .Bind <DateTime>().To(ctx => DateTime.Now) .Bind <ISettings>().Bind <ISettingsSetup>().As(Singleton).To <Settings>() .Bind <Verbosity>().To(ctx => ctx.Container.Inject <ISettings>().Verbosity) .Bind <ILog <TT> >().As(Singleton).To <Log <TT> >() .Bind <IChain <TT> >().As(Singleton).To <Chain <TT> >() .Bind <IEnvironment>().Tag(Base).To <DefaultEnvironment>() .Bind <IVirtualEnvironment>().To <VirtualEnvironment>() .Bind <IEnvironment>().To(ctx => ctx.Container.Inject <IChain <IEnvironment> >().Current) .Bind <OperatingSystem>().To(ctx => ctx.Container.Inject <IEnvironment>().OperatingSystem) .Bind <IPathNormalizer>().To(ctx => ctx.Container.Inject <IEnvironment>().PathNormalizer) .Bind <IEnumerable <EnvironmentVariable> >().To(ctx => ctx.Container.Inject <IEnvironment>().Variables) .Bind <ITeamCitySettings>().As(Singleton).To <TeamCitySettings>() .Bind <IStages>().To <Flow>() .Bind <ILocator>().As(Singleton).To <Locator>(ctx => ctx.Container.Assign(ctx.It.SearchTool, ctx.Container.Inject <OperatingSystem>() == OperatingSystem.Windows ? "where.exe" : "which")) .Bind <IToolResolver>().As(Singleton).To <ToolResolver>() .Bind <char>().Tag(ArgumentsSeparatorChar).To(ctx => CommandLineArgumentsSeparatorChar) .Bind <char>().Tag(ArgumentsQuoteChar).To(ctx => CommandLineArgumentsQuoteChar) .Bind <string>().Tag(NewLineString).To(ctx => ctx.Container.Inject <OperatingSystem>() == OperatingSystem.Windows ? "\r\n" : "\n") .Bind <string>().Tag(FlowVersionString).To(ctx => GetType().Assembly.GetName().Version.ToString()) .Bind <string>().Tag(DirectorySeparatorString).To(ctx => ctx.Container.Inject <OperatingSystem>() == OperatingSystem.Windows ? "\\" : "/") .Bind <string>().To(ctx => ctx.Container.Inject <IChain <string> >().Current) .Bind <Path>().Tag(WorkingDirectory).To(ctx => Environment.CurrentDirectory) .Bind <Path>().Tag(TempDirectory).To(ctx => System.IO.Path.GetTempPath()) .Bind <Path>().Tag(TempFile).To(ctx => new Path(System.IO.Path.Combine( ctx.Container.Inject <Path>(TempDirectory).Value, Guid.NewGuid().ToString().Replace("-", string.Empty)))) // Common .Bind <ICommandLineParser>().As(Singleton).To <CommandLineParser>() .Bind <IColorTheme>().As(Singleton).To <ColorTheme>() .Bind <IColorfulStdOut>().As(Singleton).To <ColorfulStdOut>() .Bind <IStdOut>().To(ctx => ctx.Container.Inject <IStdOut>(ctx.Container.Inject <ITeamCitySettings>().IsUnderTeamCity ? TeamCity : Base)) .Bind <IStdOut>().As(Singleton).Tag(Base).To <TeamCityStdOut>() .Bind <IStdOut>().As(Singleton).Tag(TeamCity).To <TeamCityStdOut>() .Bind <IStdErr>().To(ctx => ctx.Container.Inject <IStdErr>(ctx.Container.Inject <ITeamCitySettings>().IsUnderTeamCity ? TeamCity : Base)) .Bind <IStdErr>().As(Singleton).Tag(Base).To <TeamCityStdErr>() .Bind <IStdErr>().As(Singleton).Tag(TeamCity).To <TeamCityStdErr>() .Bind <IFileSystem>().As(Singleton).To <FileSystem>() .Bind <IConverter <MSBuildParameter, string> >().As(Singleton).To <MSBuildParameterToStringConverter>() // Command Line .Bind <ICommandLineService>().To <CommandLineService>() .Bind <IProcessFactory>().Bind <IChain <IProcessWrapper> >().As(Singleton).Tag().To <CompositeProcessFactory>() .Bind <IProcessFactory>().Tag(Base).To <ProcessFactory>() .Bind <IConverter <CommandLineArgument, string> >().To <ArgumentToStringConverter>() .Bind <IConverter <IEnumerable <CommandLineArgument>, string> >().To <ArgumentsToStringConverter>() .Bind <IProcess>().To <FlowProcess>() .Bind <IProcessListener>().Tag(StdOutErr).To <ProcessListener>() // Process Wrappers .Bind <IProcessWrapper>().Tag(CmdScriptWrapper).To <CmdProcessWrapper>() .Bind <IProcessWrapper>().Tag(ShScriptWrapper).To <ShProcessWrapper>() .Bind <IProcessWrapper>().Tag(WslScriptWrapper).To <ShProcessWrapper>() .Bind <IProcessWrapper>().Tag(DockerWrapper).To <DockerProcessWrapper>() // Docker Wrapper .Bind <IDockerWrapperService>().To <DockerWrapperService>() .Bind <IDockerArgumentsProvider>().To <DockerArgumentsProvider>() .Bind <IDockerArgumentsProvider>().Tag(DockerEnvironment).To <DockerEnvironmentArgumentsProvider>() .Bind <IDockerArgumentsProvider>().Tag(DockerVolumes).To <DockerVolumesArgumentsProvider>() // Wsl .Bind <IWslWrapperService>().To <WslWrapperService>() // Dotnet .Bind <IResponseFile>().To <MSBuildResponseFile>() .Bind <IDotnetWrapperService>().To <DotnetWrapperService>() .Bind <IDotnetBuildService>().To <DotnetBuildService>() .Bind <IProcessListener <BuildResult> >().To <BuildListener>() .Bind <IMessageProcessor>().To <MessageProcessor>() .Bind <IBuildLogFlow>().To <BuildLogFlow>() // TeamCity messages .Bind <IServiceMessageFormatter>().As(Singleton).To <ServiceMessageFormatter>() .Bind <IFlowIdGenerator>().As(Singleton).To <FlowIdGenerator>() .Bind <IServiceMessageUpdater>().As(Singleton).To <TimestampUpdater>() .Bind <TeamCityServiceMessages>().As(Singleton).To() .Bind <ITeamCityWriter>().To(ctx => ctx.Container.Inject <TeamCityServiceMessages>().CreateWriter(line => ctx.Container.Inject <IStdOut>(Base).WriteLine(line))) .Bind <IServiceMessageParser>().As(Singleton).To <ServiceMessageParser>()); }