Пример #1
0
        public void Initialize(ExtensionConfigContext context)
        {
#if NET46
            this._bindingProvider = new InjectBindingProvider(null, context.Config.LoggerFactory);
#endif
            context.AddBindingRule <InjectAttribute>().Bind(this._bindingProvider);
        }
Пример #2
0
        public async Task TryCreateAsync_WithContext_ReturnsNewBinding()
        {
            var bindingValue = "a string";
            var serviceProviderHolderMock = new Mock <IServiceProviderHolder>();
            var serviceProviderHolder     = serviceProviderHolderMock.Object;

            serviceProviderHolderMock.Setup(mock => mock.GetRequiredService(typeof(string)))
            .Returns(bindingValue);
            var injectBindingProvider = new InjectBindingProvider(serviceProviderHolder);
            var type      = typeof(ParameterInfoProvider);
            var method    = type.GetMethod("WithParameter");
            var parameter = method.GetParameters().Single(m => m.Name == "x");

            var context = new BindingProviderContext(parameter, new Dictionary <string, Type>(), CancellationToken.None);

            var binding = await injectBindingProvider.TryCreateAsync(context);

            binding.Should().NotBeNull().And.BeAssignableTo <IBinding>();
        }
Пример #3
0
 public InjectConfiguration(InjectBindingProvider injectBindingProvider) =>
 public InjectExtensionConfigProvider()
 {
     this.bindingProvider = new InjectBindingProvider();
 }
        public InjectExtensionConfigProvider(IOptions <ExecutionContextOptions> options, ILoggerFactory loggerFactory)
        {
            var appDirectory = options.Value.AppDirectory;

            this.bindingProvider = new InjectBindingProvider(appDirectory, loggerFactory);
        }
Пример #6
0
        public async Task InjectBindingProviderDoesSomething()
        {
            try
            {
                var mockService         = new Mock <ITestService>();
                var mockServiceProvider = new Mock <IServiceProvider>();
                mockServiceProvider
                .Setup(p => p.GetService(typeof(ITestService)))
                .Returns(mockService.Object);

                //mockServiceProvider
                //    .Setup(p => p.GetService(typeof(IFunctionFilter)))
                //    .Returns<IFunctionFilter>(x =>
                //    {
                //        return new ScopeCleanupFilter();
                //    });

                var mockServiceScope = new Mock <IServiceScope>();
                mockServiceScope
                .Setup(s => s.ServiceProvider)
                .Returns(mockServiceProvider.Object);

                var mockServiceScopeFactory = new Mock <IServiceScopeFactory>();
                mockServiceScopeFactory
                .Setup(f => f.CreateScope())
                .Returns(mockServiceScope.Object);

                mockServiceProvider
                .Setup(p => p.GetService(typeof(IServiceScopeFactory)))
                .Returns(mockServiceScopeFactory.Object);

                var method     = typeof(HttpTestFunction).GetMethod("Run");
                var parameters = method.GetParameters();

                var parameterInfo = parameters.First(x => x.CustomAttributes.Count() > 0 && x.CustomAttributes.Any(c => c.AttributeType == typeof(InjectAttribute)));

                var provider          = new InjectBindingProvider(mockServiceProvider.Object);
                var cancellationToken = new CancellationToken();

                var context = new BindingProviderContext(
                    parameterInfo,
                    null,
                    cancellationToken);

                var binding = await provider.TryCreateAsync(context);

                Assert.IsNotNull(binding);

                var bindingContext = new BindingContext(
                    new ValueBindingContext(
                        new FunctionBindingContext(Guid.NewGuid(), cancellationToken),
                        cancellationToken),
                    null);
                var valueProvider = await binding.BindAsync(bindingContext);

                Assert.IsNotNull(valueProvider);

                var result = await valueProvider.GetValueAsync();

                Assert.IsNotNull(result);
                Assert.IsInstanceOf <ITestService>(result);
            }
            catch (Exception e)
            {
                TestContext.WriteLine(e);
                throw;
            }
        }