コード例 #1
0
        public override IEnumerable <Variable> FindVariables(IMethodVariables chain)
        {
            _store = chain.FindVariable(typeof(IDocumentStore));

            Session = chain.TryFindVariable(typeof(IDocumentSession), VariableSource.NotServices);
            if (Session == null)
            {
                _createsSession = true;
                Session         = new Variable(typeof(IDocumentSession), this);
            }

            _isUsingPersistence = chain.IsUsingMartenPersistence();

            // Inside of messaging. Not sure how this is gonna work for HTTP yet
            _context = chain.TryFindVariable(typeof(IMessageContext), VariableSource.NotServices);

            yield return(_store);

            if (_context != null)
            {
                yield return(_context);
            }
            if (Session != null)
            {
                yield return(Session);
            }
        }
コード例 #2
0
        public override IEnumerable <Variable> FindVariables(IMethodVariables chain)
        {
            _session = chain.TryFindVariable(typeof(IQuerySession), VariableSource.All) ?? chain.FindVariable(typeof(IDocumentSession));
            yield return(_session);

            if (IsAsync)
            {
                _cancellation = chain.TryFindVariable(typeof(CancellationToken), VariableSource.All) ??
                                new Variable(typeof(CancellationToken),
                                             $"{typeof(CancellationToken).FullNameInCode()}.None");

                yield return(_cancellation);
            }
        }
コード例 #3
0
        public override IEnumerable <Variable> FindVariables(IMethodVariables chain)
        {
            if (AggregateType != null)
            {
                // You don't need it if you're in a Create method
                Aggregate = chain.TryFindVariable(AggregateType, VariableSource.All);
                if (Aggregate != null)
                {
                    yield return(Aggregate);
                }
            }

            foreach (var inner in _inner.OfType <IEventHandlingFrame>())
            {
                inner.Configure(this);
            }

            _event = chain.FindVariable(typeof(IEvent));

            yield return(_event);

            foreach (var inner in _inner)
            {
                foreach (var variable in inner.FindVariables(chain))
                {
                    yield return(variable);
                }
            }
        }
コード例 #4
0
        protected override void Generate(IMethodVariables variables, GeneratedMethod method, IMethodSourceWriter writer, Action next)
        {
            if (this.ReturnedVariable == null && this._returnType != null)
            {
                this.ReturnedVariable = variables.TryFindVariable(this._returnType);
            }

            if (this.ReturnedVariable == null)
            {
                writer.WriteLine("return;");
            }
            else
            {
                var variableIsTask    = this.ReturnedVariable.VariableType.IsGenericType && this.ReturnedVariable.VariableType.GetGenericTypeDefinition() == typeof(Task <>);
                var methodReturnsTask = method.ReturnType.IsGenericType && method.ReturnType.GetGenericTypeDefinition() == typeof(Task <>);

                // This method does not use async/await but _does_ return Task, but the variable to return is _not_ a Task<>, therefore we
                // need to use Task.FromResult to get the correct return type
                if (method.AsyncMode == AsyncMode.None && methodReturnsTask && !variableIsTask)
                {
                    // What type are we expecting to return?
                    var taskValueType = method.ReturnType.GenericTypeArguments[0];

                    writer.WriteLine(
                        $"return {typeof(Task).FullNameInCode()}.{nameof(Task.FromResult)}(({taskValueType.FullNameInCode()}){this.ReturnedVariable});");
                }
                else
                {
                    writer.WriteLine($"return {this.ReturnedVariable};");
                }
            }
        }
コード例 #5
0
        public override IEnumerable <Variable> FindVariables(IMethodVariables chain)
        {
            _isUsingPersistence = chain.IsUsingSqlServerPersistence();

            _connection = chain.FindVariable(typeof(SqlConnection));
            yield return(_connection);


            if (ShouldFlushOutgoingMessages)
            {
                _context = chain.FindVariable(typeof(IMessageContext));
            }
            else
            {
                // Inside of messaging. Not sure how this is gonna work for HTTP yet
                _context = chain.TryFindVariable(typeof(IMessageContext), VariableSource.NotServices);
            }



            if (_context != null)
            {
                yield return(_context);
            }
        }
コード例 #6
0
        private BuildStep findStep(Type type)
        {
            // INSTEAD, let's pull all variable sources
            // If not a ServiceVariable, use the KnownVariableBuildStep, otherwise use the
            // parent build step and do NOT visit its dependencies
            var variable = _method.TryFindVariable(type, VariableSource.NotServices);

            if (variable != null)
            {
                return(new KnownVariableBuildStep(variable));
            }

            var @default = _graph.FindDefault(type);

            if (@default == null)
            {
                if (EnumerableStep.IsEnumerable(type))
                {
                    return(tryFillEnumerableOfAllKnown(type));
                }

                return(null);
            }

            return(findStep(@default));
        }
コード例 #7
0
        private BuildStep findStep(Type type)
        {
            // INSTEAD, let's pull all variable sources
            // If not a ServiceVariable, use the KnownVariableBuildStep, otherwise use the
            // parent build step and do NOT visit its dependencies
            var variable = _method.TryFindVariable(type, VariableSource.NotServices);

            if (variable != null)
            {
                return(new KnownVariableBuildStep(variable));
            }

            var @default = _graph.FindDefault(type);

            if (@default?.ImplementationType != null)
            {
                var ctor = _graph.ChooseConstructor(@default.ImplementationType);
                if (ctor != null)
                {
                    return(new ConstructorBuildStep(type, @default.ImplementationType, @default.Lifetime, ctor));
                }
            }

            // TODO -- split on T[], IList<T>, IEnumerable<T>, IReadOnlyList<T>

            return(null);
        }
コード例 #8
0
        public override IEnumerable <Variable> FindVariables(IMethodVariables chain)
        {
            Context = chain.FindVariable(_dbContextType);

            // Inside of messaging. Not sure how this is gonna work for HTTP yet
            _context = chain.TryFindVariable(typeof(IMessageContext), VariableSource.NotServices) ?? chain.FindVariable(typeof(IMessageContext));

            if (_context != null)
            {
                yield return(_context);
            }
            if (Context != null)
            {
                yield return(Context);
            }
        }
コード例 #9
0
            public Variable TryFindVariable(IMethodVariables variables, Type type)
            {
                if (type == typeof(RequestTelemetry))
                {
                    // We special-case if we find a HttpContext variable to grab the RequestTelemetry from
                    // the Features collection. Otherwise we do nothing here and rely on dependency injection
                    // to find the variable
                    var httpContextVariable = variables.TryFindVariable(typeof(HttpContext));

                    if (httpContextVariable != null)
                    {
                        var features   = httpContextVariable.GetProperty(nameof(HttpContext.Features));
                        var methodCall = MethodCall.For <IFeatureCollection>(c => c.Get <RequestTelemetry>());
                        methodCall.Target = features;

                        return(methodCall.ReturnVariable);
                    }
                }

                return(null);
            }
コード例 #10
0
ファイル: BuildStepPlanner.cs プロジェクト: kassadube/jasper
        private BuildStep findStep(Type type)
        {
            var variable = _method.TryFindVariable(type, VariableSource.All);

            if (variable != null)
            {
                return(new KnownVariableBuildStep(variable));
            }

            var @default = _graph.FindDefault(type);

            if (@default?.ImplementationType != null)
            {
                var ctor = _graph.ChooseConstructor(@default.ImplementationType);
                if (ctor != null)
                {
                    return(new ConstructorBuildStep(type, @default.ImplementationType, @default.Lifetime, ctor));
                }
            }

            // split on T[], IList<T>, IEnumerable<T>, IReadOnlyList<T>

            return(null);
        }
コード例 #11
0
 internal static bool IsUsingSqlServerPersistence(this IMethodVariables method)
 {
     return(method.TryFindVariable(typeof(SqlServerBackedPersistenceMarker), VariableSource.NotServices) != null);
 }
コード例 #12
0
ファイル: ConstructorFrame.cs プロジェクト: vlisovych/lamar
 public Variable TryFindVariable(Type type, VariableSource source)
 {
     return(_inner.TryFindVariable(type, source));
 }