static RequestContext RequestContextFactory(IComponentContext context) { var httpContextAccessor = context.Resolve<IHttpContextAccessor>(); var httpContext = httpContextAccessor.Current(); if (httpContext != null) { var mvcHandler = httpContext.Handler as MvcHandler; if (mvcHandler != null) { return mvcHandler.RequestContext; } var hasRequestContext = httpContext.Handler as IHasRequestContext; if (hasRequestContext != null) { if (hasRequestContext.RequestContext != null) return hasRequestContext.RequestContext; } } else { httpContext = HttpContextBaseFactory(context); } return new RequestContext(httpContext, new RouteData()); }
private void BuildupView(IComponentContext context, DependencyObject instance) { try { if (instance == null) return; foreach (object c in LogicalTreeHelper.GetChildren(instance)) { var child = c as DependencyObject; if (child == null) continue; BuildupView(context, child); } Type viewInterfaceType = instance.GetType().GetInterface(typeof (IView<>).FullName); if (viewInterfaceType == null) return; PropertyInfo viewModelProperty = viewInterfaceType.GetProperty("ViewModel"); Type viewModelType = viewInterfaceType.GetGenericArguments()[0]; object viewModel = context.Resolve(viewModelType); viewModelProperty.SetValue(instance, viewModel, null); viewInterfaceType.GetMethod("ViewInitialized").Invoke(instance, null); } catch (Exception e) { } }
//----------------------------------------------------------------------------------------------------------------------------------------------------- public WebApplicationComponent(IWebAppEndpoint endpoint, Auto<ILogger> logger, IComponentContext componentContext) { _app = endpoint.Contract; _address = endpoint.Address; _logger = logger.Instance; _container = (ILifetimeScope)componentContext; }
/// <summary> /// Initializes a new instance of the <see cref="AutofacBytecodeProvider"/> class. /// </summary> /// <param name="container">The container.</param> /// <param name="proxyFactoryFactory">The proxy factory factory.</param> /// <param name="collectionTypeFactory">The collection type factory.</param> public AutofacBytecodeProvider(IComponentContext container, IProxyFactoryFactory proxyFactoryFactory, ICollectionTypeFactory collectionTypeFactory) { _container = container; _proxyFactoryFactory = proxyFactoryFactory; _collectionTypeFactory = collectionTypeFactory; _objectsFactory = new AutofacObjectsFactory(container); }
/// <summary> /// Configure session Factory /// </summary> /// <returns>Session</returns> private ISessionFactory CreateSessionFactory(IComponentContext a_componentContext) { return Fluently.Configure() .Database(MsSqlConfiguration.MsSql2008.ConnectionString(a_c => a_c.FromConnectionStringWithKey("Restbucks"))) .Mappings(a_m => a_m.FluentMappings.AddFromAssemblyOf<NHibernateModule>()) .BuildSessionFactory(); }
private static CloudBlobClient CreateCloudBlobClient(IComponentContext componentContext) { var connectionString = ConfigurationManager.ConnectionStrings["HadoukenStorage"].ConnectionString; var account = CloudStorageAccount.Parse(connectionString); return account.CreateCloudBlobClient(); }
public void InjectProperties(IComponentContext context, object instance, bool overrideSetValues) { if (context == null) throw new ArgumentNullException("context"); if (instance == null) throw new ArgumentNullException("instance"); var instanceType = instance.GetType(); foreach (var property in instanceType .GetProperties(BindingFlags.Public | BindingFlags.Instance) .Where(pi => pi.CanWrite)) { var propertyType = property.PropertyType; if (propertyType.IsValueType && !propertyType.IsEnum) continue; if (property.GetIndexParameters().Length != 0) continue; if (!context.IsRegistered(propertyType)) continue; var accessors = property.GetAccessors(false); if (accessors.Length == 1 && accessors[0].ReturnType != typeof(void)) continue; if (!overrideSetValues && accessors.Length == 2 && (property.GetValue(instance, null) != null)) continue; var propertyValue = context.Resolve(propertyType); property.SetValue(instance, propertyValue, null); } }
private static ISessionFactory ConfigureSessionFactory(IComponentContext context) { var connectionStringProvider = context.Resolve<IConnectionStringProvider>(); EntryMapping.CurrentSchema = connectionStringProvider.Schema; var databaseProvider = context.ResolveNamed<IDatabaseProvider>(connectionStringProvider.DatabaseProvider.ToLower()); var databaseConfiguration = databaseProvider.GetDatabaseConfiguration(connectionStringProvider); var configuration = Fluently .Configure() .Database(databaseConfiguration) .Mappings(m => { m.FluentMappings.AddFromAssembly(System.Reflection.Assembly.GetExecutingAssembly()); //Scan extensions for nHibernate mappings var extension = context.Resolve<IEnumerable<ScriptedExtension>>(); foreach (var assembly in extension.Select(provider => provider.SourceAssembly)) { m.FluentMappings.AddFromAssembly(assembly); } }) .ProxyFactoryFactory(typeof (DefaultProxyFactoryFactory)); return configuration.BuildSessionFactory(); }
public GoogleFeedService( IRepository<GoogleProductRecord> gpRepository, IProductService productService, IManufacturerService manufacturerService, FroogleSettings settings, IMeasureService measureService, MeasureSettings measureSettings, IDbContext dbContext, AdminAreaSettings adminAreaSettings, ICurrencyService currencyService, ICommonServices services, IComponentContext ctx) { _gpRepository = gpRepository; _productService = productService; _manufacturerService = manufacturerService; Settings = settings; _measureService = measureService; _measureSettings = measureSettings; _dbContext = dbContext; _adminAreaSettings = adminAreaSettings; _currencyService = currencyService; _services = services; _helper = new FeedPluginHelper(ctx, "SmartStore.GoogleMerchantCenter", "SmartStore.GoogleMerchantCenter", () => { return Settings as PromotionFeedSettings; }); }
private static ILogger CreateLogger(IComponentContext context, IEnumerable<Parameter> parameters) { // return an ILogger in response to Resolve<ILogger>(componentTypeParameter) var loggerFactory = context.Resolve<ILoggerFactory>(); var containingType = parameters.TypedAs<Type>(); return loggerFactory.CreateLogger(containingType); }
private void InjectPropertiesForChildViews(IComponentContext context, IPresentationBusConfiguration bus, UIElement uiElement) { var userControl = uiElement as UserControl; if (userControl != null) { InjectProperties(context, bus, userControl.Content); return; } var panel = uiElement as Panel; if (panel != null) { foreach (var child in panel.Children) { InjectProperties(context, bus, child); } return; } var contentControl = uiElement as ContentControl; if (contentControl != null) { InjectProperties(context, bus, contentControl.Content as UIElement); return; } }
public EventStoreProxy(IComponentContext container) { _container = container; //Ensure we only set up the connection once lock (CreateConnectionLock) { if (_eventStoreConn == null) { var connSettings = ConnectionSettings.Create() .KeepReconnecting() .KeepRetrying(); //TODO: get config value for address, port and user account _eventStoreConn = EventStoreConnection.Create(connSettings, new IPEndPoint(IPAddress.Loopback, 1113)); _eventStoreConn.Disconnected += EventStoreConnDisconnected; _eventStoreConn.ErrorOccurred += EventStoreConnErrorOccurred; _eventStoreConn.Reconnecting += EventStoreConnReconnecting; _eventStoreConn.Connected += EventStoreConnConnected; _eventStoreConn.ConnectAsync().Wait(); SubscribeToStreamComment(); SubscribeToStreamTodo(); } } }
/// <summary> /// Activate an instance in the provided context. /// </summary> /// <param name="context">Context in which to activate instances.</param> /// <param name="parameters">Parameters to the instance.</param> /// <returns>The activated instance.</returns> /// <remarks> /// The context parameter here should probably be ILifetimeScope in order to reveal Disposer, /// but will wait until implementing a concrete use case to make the decision /// </remarks> public Func<object> GetFactory(IComponentContext context, IEnumerable<Parameter> parameters) { if (context == null) throw new ArgumentNullException("context"); if (parameters == null) throw new ArgumentNullException("parameters"); return () => _instance; }
public AgencyBanks(IComponentContext container) { this.iContainer = container; queueConfiguration = iContainer.Resolve<IQueueConfiguration>(); publisher = iContainer.Resolve<IExchangePublisher<Job>>(); publisher.Declare(queueConfiguration.ResponseExchangeName); }
private object[] GetConstructurArgs(IComponentContext context) { if (context.NamedArgs != null && context.NamedArgs.Count > 0) return context.NamedArgs.Values.ToArray(); if (context.Args != null && context.Args.Length > 0) return context.Args; //const BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public; var impType = context.Component.Implementation; object o; if (context.Component.ExtendedProperties.TryGetValue(impType.FullName + ":ctorInjections", out o)) { var ctors = o as ConstructorInjection[]; if (ctors != null && ctors.Length > 0) { var validConstructorBinding = ctors.FirstOrDefault(p => p.IsMatch); if (validConstructorBinding != null) return validConstructorBinding.Dependencies.Select(p => p.ValueProvider()).ToArray(); } } return null; }
/// <summary> /// Override to return a closure that injects properties into a target. /// </summary> /// <param name="context">The context.</param> /// <returns>The injector.</returns> protected override Func<object, object> GetInjector(IComponentContext context) { if (context == null) throw new ArgumentNullException("context"); return context.InjectProperties<object>; }
/// <summary> /// Initializes a new instance of the <see cref="PreparingEventArgs"/> class. /// </summary> /// <param name="service">Service which is preparing</param> /// <param name="context">The context.</param> /// <param name="component">The component.</param> /// <param name="parameters">The parameters.</param> public PreparingEventArgs(Service service, IComponentContext context, IComponentRegistration component, IEnumerable<Parameter> parameters) { _service = Enforce.ArgumentNotNull(service, "service"); _context = Enforce.ArgumentNotNull(context, "context"); _component = Enforce.ArgumentNotNull(component, "component"); _parameters = Enforce.ArgumentNotNull(parameters, "parameters"); }
private static ITwitterFeed OnStartupExtracted(IComponentContext ctx, bool useTwitter) { if (useTwitter) return ctx.Resolve<TwitterFeedAsync>(); else return ctx.Resolve<FakeTwitterFeed>(); }
public static void InjectProperties(IComponentContext context, object instance) { var properties = instance.GetType().GetFields( BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (var fieldInfo in properties) { var propertyType = fieldInfo.FieldType; if (propertyType.IsValueType || !context.IsRegistered(propertyType)) { continue; } if (HasImportAttribute(fieldInfo)) { if (fieldInfo.GetValue(instance) != null) { continue; // do not overwrite existing non-null values } var obj = context.Resolve(propertyType); if (obj == null) { throw new DependencyResolutionException( $"Unable to resolve dependency import on {instance.GetType()} -> {fieldInfo}"); } fieldInfo.SetValue(instance, obj); } } }
internal void Start(IComponentContext context) { var engine = context.Resolve<ClientEngine>(); var dhtListner = context.Resolve<DhtListener>(); var dht = context.Resolve<IDhtEngine>(); var settingsUtility = context.Resolve<ISettingsUtility>(); var port = settingsUtility.Read(ApplicationConstants.TorrentPortKey, ApplicationConstants.DefaultTorrentPort); OpenPort(port); // register the dht engine engine.RegisterDht(dht); // start the dht listener dhtListner.Start(); // annnnnddd start the dht engine engine.DhtEngine.Start(); // clear up torrent folder Task.Factory.StartNew(async () => { var torrentsFolder = engine.Settings.SaveFolder; await StorageHelper.DeleteFolderContentAsync(torrentsFolder); }); }
public EditorEnvironment( MainEditorWindow mainEditorWindow, IResourceManager resourceManager, IComponentContext context) { this.mainEditorWindow = mainEditorWindow; this.resourceManager = resourceManager; this.context = context; }
public static BusBuilderConfiguration WithAutofacDefaults(this BusBuilderConfiguration configuration, IComponentContext componentContext) { return configuration .WithTypesFrom(componentContext.Resolve<ITypeProvider>()) .WithDependencyResolver(componentContext.Resolve<IDependencyResolver>()) ; }
public BinaryResourceFormat( IResourceManager resourceManager, IComponentContext context, IResourceErrorHandler errorHandler) { this.resourceManager = resourceManager; this.context = context; this.errorHandler = errorHandler; }
private ILogger CreateLogger(IComponentContext resolver) { var configurations = resolver.ResolveAll<LogSink.Configuration>(); var baseConfiguration = resolver.Resolve<LoggerConfiguration>(); return configurations.Aggregate(baseConfiguration, (_, configure) => configure(_)).CreateLogger(); }
/// <summary> /// Construct a new ConstructorParameterBinding. /// </summary> /// <param name="ci">ConstructorInfo to bind.</param> /// <param name="availableParameters">Available parameters.</param> /// <param name="context">Context in which to construct instance.</param> public ConstructorParameterBinding( ConstructorInfo ci, IEnumerable<Parameter> availableParameters, IComponentContext context) { _canInstantiate = true; _ci = Enforce.ArgumentNotNull(ci, "ci"); if (availableParameters == null) throw new ArgumentNullException("availableParameters"); if (context == null) throw new ArgumentNullException("context"); var parameters = ci.GetParameters(); _valueRetrievers = new Func<object>[parameters.Length]; for (int i = 0; i < parameters.Length; ++i) { var pi = parameters[i]; bool foundValue = false; foreach (var param in availableParameters) { Func<object> valueRetriever; if (param.CanSupplyValue(pi, context, out valueRetriever)) { _valueRetrievers[i] = valueRetriever; foundValue = true; break; } } if (!foundValue) { _canInstantiate = false; _firstNonBindableParameter = pi; break; } } }
public EditorFactory(Package package, IComponentContext context) { Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering {0} constructor", this)); this.editorPackage = package; this.context = context; }
//private GLControl glControl; #region Constructors and Destructors public Base3DEditor( IComponentContext context, IEditorOptions<Base3DEditorOptions> options, Base3DEditorContent content) { this.options = options; this.content = content; this.graphicsContext = context.Resolve<ToeGraphicsContext>(); this.camera = new EditorCamera(context.Resolve<IEditorOptions<EditorCameraOptions>>()); this.camera.PropertyChanged += this.OnCameraPropertyChanged; this.InitializeComponent(); this.Dock = DockStyle.Fill; //this.glControl = new GLControl(GraphicsMode.Default, 1, 0, GraphicsContextFlags.Default); //this.glControl.Dock = DockStyle.Fill; this.glControl.Load += this.GLControlLoad; this.glControl.Paint += this.GLControlPaint; this.glControl.Resize += this.GLControlResize; this.Controls.Add(this.glControl); this.glControl.MouseMove += this.OnSceneMouseMove; this.glControl.MouseEnter += this.OnSceneMouseEnter; this.glControl.MouseLeave += this.OnSceneMouseLeave; this.glControl.MouseWheel += this.OnSceneMouseWheel; this.glControl.KeyDown += this.OnControlKeyDown; this.glControl.KeyUp += this.OnControlKeyUp; this.glControl.GotFocus += this.OnSceneGotFocus; this.glControl.LostFocus += this.OnSceneLostFocus; this.Camera.LookAt(new Vector3(512, 64, 1024), new Vector3(0, 0, 0)); this.CameraController = new TargetCameraController { Camera = this.Camera }; this.yUpToolStripMenuItem.Click += this.SelectYUp; this.zUpToolStripMenuItem.Click += this.SelectZUp; this.UpdateCoordinateSystemIcon(); this.UpdateLighingIcon(); this.UpdateWireframeIcon(); this.UpdateNormalIcon(); }
private object GetObjectMappers(IComponentContext resolveContext) { var mappers = new List<IObjectMapper>(resolveContext.Resolve<IEnumerable<IObjectMapper>>()); mappers.AddRange(MapperRegistry.Mappers); return mappers; }
public PayPalExpressController( IPaymentService paymentService, IOrderService orderService, IOrderProcessingService orderProcessingService, ILogger logger, PaymentSettings paymentSettings, ILocalizationService localizationService, OrderSettings orderSettings, ICurrencyService currencyService, CurrencySettings currencySettings, IOrderTotalCalculationService orderTotalCalculationService, ICustomerService customerService, IGenericAttributeService genericAttributeService, IComponentContext ctx, ICommonServices services, IStoreService storeService) { _paymentService = paymentService; _orderService = orderService; _orderProcessingService = orderProcessingService; _logger = logger; _paymentSettings = paymentSettings; _localizationService = localizationService; _orderSettings = orderSettings; _currencyService = currencyService; _currencySettings = currencySettings; _orderTotalCalculationService = orderTotalCalculationService; _customerService = customerService; _genericAttributeService = genericAttributeService; _services = services; _storeService = storeService; _helper = new PluginHelper(ctx, "SmartStore.PayPal", "Plugins.Payments.PayPalExpress"); T = NullLocalizer.Instance; }
public CommandDispatcher(IComponentContext context) { _context = context; }
public AutofacQueryFactory(IComponentContext c) { this.c = c; }
public ViewFactory(IComponentContext componentContext) { _componentContext = componentContext; Instance = this; }
public static ApplicationUserManager Create(IDataProtectionProvider dataProtectionProvider, IComponentContext context) { var manager = new ApplicationUserManager(context.Resolve <IUserStore <ApplicationUser> >()); // Configure validation logic for usernames manager.UserValidator = new UserValidator <ApplicationUser>(manager) { AllowOnlyAlphanumericUserNames = false, RequireUniqueEmail = true }; // Configure validation logic for passwords manager.PasswordValidator = new PasswordValidator { RequireNonLetterOrDigit = false, RequireDigit = false, RequireLowercase = false, RequireUppercase = false }; if (dataProtectionProvider != null) { manager.UserTokenProvider = new DataProtectorTokenProvider <ApplicationUser>(context.Resolve <IDataProtector>()); } return(manager); }
public CommandFactory(IComponentContext container) { this.container = container ?? throw new ArgumentNullException(nameof(container)); }
public AutofacMessageBusDependencyResolver(IComponentContext container) : this(container, container.Resolve <ILogger <AutofacMessageBusDependencyResolver> >()) { }
public AutofacMessageBusDependencyResolver(IComponentContext container, ILogger <AutofacMessageBusDependencyResolver> logger) { _logger = logger; _componentContext = container; _lifetimeScope = container as ILifetimeScope; }
public AutofacDependencyResolver([NotNull] IComponentContext kernel) { _context = kernel ?? throw new ArgumentNullException(nameof(kernel)); }
public WorkContextImplementation(IComponentContext componentContext) { _componentContext = componentContext; _workContextStateProviders = componentContext.Resolve <IEnumerable <IWorkContextStateProvider> >(); }
public WcfServiceHostFactory(IComponentContext container) { _container = container; }
public WcfInstanceProvider(IComponentContext container) { _container = container; }
public AutofacDependencyResolver(IComponentContext ctx) { this.ctx = ctx; }
public InMemoryBus(IComponentContext componentContext) { _componentContext = componentContext; }
public ProviderManager(IComponentContext ctx, ICommonServices services, PluginMediator pluginMediator) { this._ctx = ctx; this._services = services; this._pluginMediator = pluginMediator; }
private static ILogger GetInstallLogger(IComponentContext context) { return(context.Resolve <ILoggerFactory>().CreateLogger("Install")); }
/// <summary> /// Returns true if the parameter is able to provide a value to a particular site. /// </summary> /// <param name="pi">Constructor, method, or property-mutator parameter.</param> /// <param name="context">The component context in which the value is being provided.</param> /// <param name="valueProvider">If the result is true, the valueProvider parameter will /// be set to a function that will lazily retrieve the parameter value. If the result is false, /// will be set to null.</param> /// <returns>True if a value can be supplied; otherwise, false.</returns> public abstract bool CanSupplyValue(ParameterInfo pi, IComponentContext context, out Func <object> valueProvider);
/// <summary> /// Initializes a new instance of the <see cref="LocalDispatcher"/> class. /// </summary> /// <param name="components">The configured <see cref="IComponentContext"/>.</param> public LocalDispatcher(IComponentContext components) { _components = components; _environmentContext = components.Resolve <IEnvironmentContext>(); _requestContext = components.Resolve <IRequestContext>(); }
/// <summary> /// Executes the startable and auto-activate components in a context. /// </summary> /// <param name="properties">The set of properties used during component registration.</param> /// <param name="componentContext"> /// The <see cref="IComponentContext"/> in which startable services should execute. /// </param> internal static void StartStartableComponents(IDictionary <string, object?> properties, IComponentContext componentContext) { var componentRegistry = componentContext.ComponentRegistry; try { properties[MetadataKeys.StartOnActivatePropertyKey] = true; // We track which registrations have already been auto-activated by adding // a metadata value. If the value is present, we won't re-activate. This helps // in the container update situation. var startableService = new TypedService(typeof(IStartable)); foreach (var registration in componentRegistry.ServiceRegistrationsFor(startableService).Where(r => !r.Metadata.ContainsKey(MetadataKeys.AutoActivated))) { try { var request = new ResolveRequest(startableService, registration, Enumerable.Empty <Parameter>()); componentContext.ResolveComponent(request); } finally { registration.Metadata[MetadataKeys.AutoActivated] = true; } } var autoActivateService = new AutoActivateService(); foreach (var registration in componentRegistry.ServiceRegistrationsFor(autoActivateService).Where(r => !r.Metadata.ContainsKey(MetadataKeys.AutoActivated))) { try { var request = new ResolveRequest(autoActivateService, registration, Enumerable.Empty <Parameter>()); componentContext.ResolveComponent(request); } catch (DependencyResolutionException ex) { throw new DependencyResolutionException(string.Format(CultureInfo.CurrentCulture, ContainerBuilderResources.ErrorAutoActivating, registration), ex); } finally { registration.Metadata[MetadataKeys.AutoActivated] = true; } } } finally { properties.Remove(MetadataKeys.StartOnActivatePropertyKey); } }
public QueryDispatcher(IComponentContext componentContext) { _componentContext = componentContext; }
public HyperwayOutboundComponent(IComponentContext context) { this.context = context; }
public HierarchicalNavigation(IComponentContext componentContext) { _componentContext = componentContext; }
public CommandBus(IComponentContext context) { _context = context; }
public AdjustmentLettersRequestProcessorFactory(IComponentContext container) { this.container = container; }
public void Autofac_IComponentContext( ) { IComponentContext instance = Factory.Current.Resolve <IComponentContext>( ); Assert.That(instance, Is.Not.Null); }
public CommandDispatcher(IComponentContext context) { _context = context ?? throw new ArgumentNullException(nameof(context)); }
public DialogFactory(IComponentContext scope) { SetField.NotNull(out Scope, nameof(scope), scope); }
public ListPathConstraintUpdator(IListPathConstraint listPathConstraint, IComponentContext componentContext, IListCategoryPathConstraint listCategoryPathConstraint) { this.listPathConstraint = listPathConstraint; this.componentContext = componentContext; this.listCategoryPathConstraint = listCategoryPathConstraint; }
public virtual object ResolveParameter(ParameterInfo p, IComponentContext c = null) { return((c ?? _container.Value).Resolve(p.ParameterType)); }
public ContosoFlowersDialogFactory(IComponentContext scope) : base(scope) { }
public NHibernateBoxQueryEvaluator(ILog log, RepositoryFinder repoFinder, IComponentContext context) { this.log = log; _repoFinder = repoFinder; this.context = context; }