Exemple #1
0
        /// <summary>
        /// Initializes the app by setting up dependency injection
        /// </summary>
        /// <param name="context"></param>
        public void Initialize(ExtensionConfigContext context)
        {
            // allow derived classes to register services
            var services = new T().Configure(new ServiceCollection().AddSingleton(context.Config.LoggerFactory));

            // create injection scope manager
            var injectionScopeManager = new InjectionScopeManager(services.BuildServiceProvider(true));

            // create filter for managing scopes
            var injectionScopeFilter = new InjectionScopeFilter(injectionScopeManager);

            context.Config.RegisterExtension <IFunctionInvocationFilter>(injectionScopeFilter);
            context.Config.RegisterExtension <IFunctionExceptionFilter>(injectionScopeFilter);

            // map injection binding provider to the inject attribute
            context.AddBindingRule <InjectAttribute>().Bind(new InjectBindingProvider(injectionScopeManager));
        }
 /// <summary>
 /// Binds the value by resolving it from a <see cref="BindingContext"/>
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 public Task <IValueProvider> BindAsync(BindingContext context)
 => BindAsync(InjectionScopeManager.GetServiceProvider(context.FunctionInstanceId).GetRequiredService(Parameter.ParameterType), context.ValueContext);
 /// <summary>
 /// Creates an <see cref="InjectionScopeFilter"/>
 /// </summary>
 /// <param name="scopeManager"></param>
 public InjectionScopeFilter(InjectionScopeManager scopeManager) => ScopeManager = scopeManager;