public IToken Register(IMutableContainer container, Predicate <Key> filter, params IInterceptor[] interceptors)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }
            if (filter == null)
            {
                throw new ArgumentNullException(nameof(filter));
            }
            if (interceptors == null)
            {
                throw new ArgumentNullException(nameof(interceptors));
            }
            var info = new InterceptorsInfo(filter, interceptors);

            lock (_interceptors)
            {
                _interceptors.Add(info);
            }

            return(Disposable.Create(() =>
            {
                lock (_interceptors)
                {
                    _interceptors.Remove(info);
                }
            }).AsTokenOf(container));
        }
 /// <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());
 }
Example #3
0
 public static IBinding <T> Bind <T>([NotNull] this IMutableContainer container)
 {
     if (container == null)
     {
         throw new ArgumentNullException(nameof(container));
     }
     return(new Binding <T>(container, typeof(T)));
 }
Example #4
0
        public void Initialize()
        {
            var builder = new ContainerBuilder();

            builder.RegisterType <Singleton>().SingleInstance();
            builder.RegisterType <FuncSingleton>().SingleInstance();
            _mutable = new MutableContainer(builder);
        }
Example #5
0
 // ReSharper disable once StaticMemberInGenericType
 public Binding([NotNull] IMutableContainer container, [NotNull][ItemNotNull] params Type[] types)
 {
     Container          = container ?? throw new ArgumentNullException(nameof(container));
     Tokens             = Enumerable.Empty <IToken>();
     Types              = types ?? throw new ArgumentNullException(nameof(types));
     Lifetime           = default(ILifetime);
     Tags               = Enumerable.Empty <object>();
     AutowiringStrategy = default(IAutowiringStrategy);
 }
        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>());
        }
Example #7
0
 public MyClass(
     IContainer currentContainer,
     IMutableContainer newChildContainer,
     Func <IMutableContainer> childContainerFactory,
     Func <string, IMutableContainer> nameChildContainerFactory)
 {
     CurrentContainer    = currentContainer;
     ChildContainer1     = newChildContainer;
     ChildContainer2     = childContainerFactory();
     NamedChildContainer = nameChildContainerFactory("Some name");
 }
Example #8
0
        public static bool RemoveById <T>(this IMutableContainer <T> container, string id)
            where T : INode
        {
            var item = container[id];

            if (item == null)
            {
                return(false);
            }
            return(container.Remove(item));
        }
Example #9
0
        public void FinalizeExtension()
        {
            if (Instance != null)
            {
                return;
            }

            Builder.RegisterSource(new AnyConcreteTypeNotAlreadyRegisteredSource());
            Instance = new MutableContainer(Builder);
            SetLifetimeScope(Instance);
            FinalizeRegistry();
        }
Example #10
0
 public static IToken Intercept <T>([NotNull] this IMutableContainer container, [NotNull][ItemNotNull] params IInterceptor[] interceptors)
 {
     if (container == null)
     {
         throw new ArgumentNullException(nameof(container));
     }
     if (interceptors == null)
     {
         throw new ArgumentNullException(nameof(interceptors));
     }
     return(container.Intercept(new Key(typeof(T)), interceptors));
 }
        /// <inheritdoc />
        public IEnumerable <IToken> Apply(IMutableContainer container)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }
            yield return(container.Register(ctx => new Lazy <TT>(() => ctx.Container.Inject <TT>(ctx.Key.Tag), true), null, AnyTag));

            yield return(container.Register(ctx => ctx.Container.TryInjectValue <TTS>(ctx.Key.Tag), null, AnyTag));

            yield return(container.Register(ctx => new ThreadLocal <TT>(() => ctx.Container.Inject <TT>(ctx.Key.Tag)), null, AnyTag));
        }
Example #12
0
        public static IToken Intercept([NotNull] this IMutableContainer container, Key key, [NotNull][ItemNotNull] params IInterceptor[] interceptors)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }
            if (interceptors == null)
            {
                throw new ArgumentNullException(nameof(interceptors));
            }

            return(container.GetRegistry().Register(container, (targetKey) => Filter(targetKey, key), interceptors));
        }
Example #13
0
        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)
            {
                // 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>());
            }
Example #15
0
 public Registration(
     [NotNull] IMutableContainer container,
     [NotNull] IObserver <ContainerEvent> eventObserver,
     [NotNull] IDependency dependency,
     [CanBeNull] ILifetime lifetime,
     [NotNull] IDisposable resource,
     [NotNull] ICollection <Key> keys)
 {
     Container      = container;
     _eventObserver = eventObserver;
     Dependency     = dependency;
     Lifetime       = lifetime;
     _resource      = resource;
     Keys           = keys;
 }
Example #16
0
            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()));
            }
Example #17
0
 public static IBinding <object> Bind([NotNull] this IMutableContainer container, [NotNull][ItemNotNull] params Type[] types)
 {
     if (container == null)
     {
         throw new ArgumentNullException(nameof(container));
     }
     if (types == null)
     {
         throw new ArgumentNullException(nameof(types));
     }
     if (types.Length == 0)
     {
         throw new ArgumentException("Value cannot be an empty collection.", nameof(types));
     }
     return(new Binding <object>(container, types));
 }
Example #18
0
 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)));
 }
Example #19
0
 public static IToken Intercept([NotNull] this IMutableContainer container, [NotNull] Predicate <Key> filter, [NotNull][ItemNotNull] params IInterceptor[] interceptors)
 {
     if (container == null)
     {
         throw new ArgumentNullException(nameof(container));
     }
     if (filter == null)
     {
         throw new ArgumentNullException(nameof(filter));
     }
     if (interceptors == null)
     {
         throw new ArgumentNullException(nameof(interceptors));
     }
     return(container.GetRegistry().Register(container, filter, interceptors));
 }
        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>());
        }
Example #21
0
        /// <summary>
        /// Traces container actions through a handler.
        /// </summary>
        /// <param name="container">The target container to trace.</param>
        /// <param name="onTraceEvent">The trace handler.</param>
        /// <returns>The trace token.</returns>
        public static IToken Trace([NotNull] this IMutableContainer container, [NotNull] Action <TraceEvent> onTraceEvent)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }
            if (onTraceEvent == null)
            {
                throw new ArgumentNullException(nameof(onTraceEvent));
            }

            return(new Token(
                       container,
                       container
                       .ToTraceSource()
                       .Subscribe(
                           onTraceEvent,
                           error => { },
                           () => { })));
        }
Example #22
0
        public IEnumerable <IToken> Apply(IMutableContainer container)
        {
            // Create ASP .NET core feature
            var aspNetCoreFeature = new AspNetCoreFeature();

            // Configure services
            aspNetCoreFeature
            .AddEntityFrameworkInMemoryDatabase()
            .AddDbContext <Db>(options => options.UseInMemoryDatabase("Sample DB"), ServiceLifetime.Singleton);

            // Id generator
            var id         = new Id();
            var generateId = new Func <Id>(() => id = new Id(id));

            yield return(container
                         // Apply ASP.NET core feature
                         .Apply(aspNetCoreFeature)
                         // Add required bindings
                         .Bind <Id>().To(ctx => generateId())
                         .Bind <Person>().To <Person>());
        }
Example #23
0
        public static IToken Register([NotNull] this IMutableContainer container, [NotNull][ItemNotNull] IEnumerable <Type> types, [NotNull] IDependency dependency, [CanBeNull] ILifetime lifetime = null, [CanBeNull][ItemCanBeNull] object[] tags = null)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }
            if (types == null)
            {
                throw new ArgumentNullException(nameof(types));
            }
            if (dependency == null)
            {
                throw new ArgumentNullException(nameof(dependency));
            }
            var keys =
                from type in types
                from tag in tags ?? DefaultTags
                select new Key(type, tag);

            return(container.TryRegisterDependency(keys, dependency, lifetime, out var dependencyToken)
                ? dependencyToken
                : container.Resolve <ICannotRegister>().Resolve(container, keys, dependency, lifetime));
        }
Example #24
0
        /// <inheritdoc />
        public IEnumerable <IToken> Apply(IMutableContainer container)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }
            yield return(container.Register(new[] { typeof(IEnumerable <TT>) }, new EnumerableDependency(), null, new[] { Key.AnyTag }));

            yield return(container.Register(new[] { typeof(TT[]) }, new ArrayDependency(), null, new [] { Key.AnyTag }));

            yield return(container.Register <List <TT>, IList <TT>, ICollection <TT> >(ctx => new List <TT>(ctx.Container.Inject <TT[]>(ctx.Key)), null, new[] { Key.AnyTag }));

            yield return(container.Register <HashSet <TT>, ISet <TT> >(ctx => new HashSet <TT>(ctx.Container.Inject <TT[]>(ctx.Key)), null, new[] { Key.AnyTag }));

            yield return(container.Register <IObservable <TT> >(ctx => new Observable <TT>(ctx.Container.Inject <IEnumerable <TT> >(ctx.Key)), null, new[] { Key.AnyTag }));

#if !NET40
            yield return(container.Register <ReadOnlyCollection <TT>, IReadOnlyList <TT>, IReadOnlyCollection <TT> >(ctx => new ReadOnlyCollection <TT>(ctx.Container.Inject <TT[]>(ctx.Key)), null, new[] { Key.AnyTag }));
#endif
#if NET5_0_OR_GREATER || NETCOREAPP3_0 || NETCOREAPP3_1 || NETSTANDARD2_1
            yield return(container.Register <IAsyncEnumerable <TT> >(ctx => new AsyncEnumeration <TT>(ctx.Container.Inject <IEnumerable <TT> >(ctx.Key)), null, new[] { Key.AnyTag }));
#endif
        }
Example #25
0
 public Token([NotNull] IMutableContainer container, [NotNull] IDisposable dependencyToken)
 {
     Container        = container ?? throw new ArgumentNullException(nameof(container));
     _dependencyToken = dependencyToken ?? throw new ArgumentNullException(nameof(dependencyToken));
 }
Example #26
0
        /// <inheritdoc />
        public IEnumerable <IToken> Apply(IMutableContainer container)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }
            yield return(container.Register(ctx => new Tuple <TT>(ctx.Container.Inject <TT>(ctx.Key.Tag)), null, AnyTag));

            yield return(container.Register(ctx => new Tuple <TT1, TT2>(
                                                ctx.Container.Inject <TT1>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT2>(ctx.Key.Tag)), null, AnyTag));

            yield return(container.Register(ctx => new Tuple <TT1, TT2, TT3>(
                                                ctx.Container.Inject <TT1>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT2>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT3>(ctx.Key.Tag)), null, AnyTag));

            yield return(container.Register(ctx => new Tuple <TT1, TT2, TT3, TT4>(
                                                ctx.Container.Inject <TT1>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT2>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT3>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT4>(ctx.Key.Tag)), null, AnyTag));

            yield return(container.Register(ctx => new Tuple <TT1, TT2, TT3, TT4, TT5>(
                                                ctx.Container.Inject <TT1>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT2>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT3>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT4>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT5>(ctx.Key.Tag)), null, AnyTag));

            yield return(container.Register(ctx => new Tuple <TT1, TT2, TT3, TT4, TT5, TT6>(
                                                ctx.Container.Inject <TT1>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT2>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT3>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT4>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT5>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT6>(ctx.Key.Tag)), null, AnyTag));

            yield return(container.Register(ctx => new Tuple <TT1, TT2, TT3, TT4, TT5, TT6, TT7>(
                                                ctx.Container.Inject <TT1>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT2>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT3>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT4>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT5>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT6>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT7>(ctx.Key.Tag)), null, AnyTag));

            yield return(container.Register(ctx => new Tuple <TT1, TT2, TT3, TT4, TT5, TT6, TT7, TT8>(
                                                ctx.Container.Inject <TT1>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT2>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT3>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT4>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT5>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT6>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT7>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT8>(ctx.Key.Tag)), null, AnyTag));

#if !NET40 && !NET403 && !NET45 && !NET45 && !NET451 && !NET452 && !NET46 && !NET461 && !NET462 && !NETCOREAPP1_0 && !NETCOREAPP1_1 && !NETSTANDARD1_0 && !NETSTANDARD1_1 && !NETSTANDARD1_2 && !NETSTANDARD1_3 && !NETSTANDARD1_4 && !NETSTANDARD1_5 && !NETSTANDARD1_6 && !WINDOWS_UWP
            yield return(container.Register(ctx => CreateTuple(
                                                ctx.Container.Inject <TT1>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT2>(ctx.Key.Tag)), null, AnyTag));

            yield return(container.Register(ctx => CreateTuple(
                                                ctx.Container.Inject <TT1>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT2>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT3>(ctx.Key.Tag)), null, AnyTag));

            yield return(container.Register(ctx => CreateTuple(
                                                ctx.Container.Inject <TT1>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT2>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT3>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT4>(ctx.Key.Tag)), null, AnyTag));

            yield return(container.Bind <(TT1, TT2, TT3, TT4, TT5)>().AnyTag().To(ctx => CreateTuple(
                                                                                      ctx.Container.Inject <TT1>(ctx.Key.Tag),
                                                                                      ctx.Container.Inject <TT2>(ctx.Key.Tag),
                                                                                      ctx.Container.Inject <TT3>(ctx.Key.Tag),
                                                                                      ctx.Container.Inject <TT4>(ctx.Key.Tag),
                                                                                      ctx.Container.Inject <TT5>(ctx.Key.Tag))));

            yield return(container.Register(ctx => CreateTuple(
                                                ctx.Container.Inject <TT1>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT2>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT3>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT4>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT5>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT6>(ctx.Key.Tag)), null, AnyTag));

            yield return(container.Register(ctx => CreateTuple(
                                                ctx.Container.Inject <TT1>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT2>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT3>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT4>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT5>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT6>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT7>(ctx.Key.Tag)), null, AnyTag));

            yield return(container.Register(ctx => CreateTuple(
                                                ctx.Container.Inject <TT1>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT2>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT3>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT4>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT5>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT6>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT7>(ctx.Key.Tag),
                                                ctx.Container.Inject <TT8>(ctx.Key.Tag)), null, AnyTag));
#endif
        }
 public IEnumerable <IToken> Apply(IMutableContainer container)
 {
     yield return(container
                  .Bind <Page>().As(Singleton).To <MainPage>());
 }
Example #28
0
 public IEnumerable <IToken> Apply(IMutableContainer container)
 {
     // Design time View Models
     yield return(container
                  .Bind <IClockViewModel>().To <ClockViewModelDesignTime>());
 }
Example #29
0
        /// <inheritdoc />
        public IEnumerable <IToken> Apply(IMutableContainer container)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }
            yield return(container.Register(ctx => FoundCyclicDependency.Shared));

            yield return(container.Register(ctx => CannotBuildExpression.Shared));

            yield return(container.Register(ctx => CannotRegister.Shared));

            yield return(container.Register(ctx => CannotResolveConstructor.Shared));

            yield return(container.Register(ctx => CannotResolveType.Shared));

            yield return(container.Register(ctx => CannotResolveGenericTypeArgument.Shared));

            yield return(container.Register(ctx => DefaultAutowiringStrategy.Shared));

            // Lifetimes
            yield return(container.Register <ILifetime>(ctx => new SingletonLifetime(true), null, new object[] { Lifetime.Singleton }));

            yield return(container.Register <ILifetime>(ctx => new ContainerSingletonLifetime(), null, new object[] { Lifetime.ContainerSingleton }));

            yield return(container.Register <ILifetime>(ctx => new ScopeSingletonLifetime(), null, new object[] { Lifetime.ScopeSingleton }));

            yield return(container.Register <ILifetime>(ctx => new ScopeTransientLifetime(), null, new object[] { Lifetime.ScopeTransient }));

            yield return(container.Register <ILifetime>(ctx => new ScopeRootLifetime(), null, new object[] { Lifetime.ScopeRoot }));

            yield return(container.Register <ILifetime>(ctx => new DisposingLifetime(), null, new object[] { Lifetime.Disposing }));

            // Scope
            yield return(container.Register <IScopeToken>(ctx => Scope.Current));

            yield return(container.Register <IScope>(ctx => new Scope(ctx.Container.Inject <ILockObject>(), false)));

            // Current container
            yield return(container.Register <IContainer, IObservable <ContainerEvent> >(ctx => ctx.Container));

            // New child container
            yield return(container.Register <IMutableContainer>(
                             ctx => new Container(
                                 ctx.Args.Length == 1 ? Container.CreateContainerName(ctx.Args[0] as string) : Container.CreateContainerName(string.Empty),
                                 ctx.Container,
                                 ctx.Container.Inject <ILockObject>())));

            yield return(container.Register <Func <IMutableContainer> >(ctx => () => ctx.Container.Inject <IMutableContainer>()));

            yield return(container.Register <Func <string, IMutableContainer> >(ctx => name => ctx.Container.Resolve <IMutableContainer>(name)));

            // Metadata
            yield return(container.Register(ctx => ctx.Container.Inject <IBuildContext>().Parent.Key));

            yield return(container.Register(ctx => ctx.Container.Inject <IBuildContext>().Parent.Key.Tag.AsTag()));

            yield return(container.Register(ctx => ContainerEventToStringConverter.Shared));

            yield return(container.Register(ctx => TypeToStringConverter.Shared));

            // Core features
            yield return(container.Apply <ResolveUnboundFeature>());
        }
Example #30
0
 public TeamCityMsBuildLogger(IMutableContainer container)
 {
     _container = container;
     _logger    = _container.Resolve <INodeLogger>();
 }