/// <summary> /// Init constructor. /// </summary> public ServiceCreationEventArgs(IServiceProviderEx provider, object registeredServiceID, object requestedServiceID, object[] serviceArgs) { Provider = provider; RegisteredServiceID = registeredServiceID; RequestedServiceID = requestedServiceID; ServiceArgs = serviceArgs; }
/// <summary> /// Initializes a new instance of the <see cref="LocalizationConfiguration"/> class. /// </summary> public LocalizationConfiguration() { IServiceProviderEx serviceProvider = ServiceProviderLocator.Instance.LocateProvider(); _SupportedCultures = new List <CultureInfo>(); _Logger = serviceProvider.GetService <ILogger>(); }
private static object PrivateCreation(IServiceProviderEx provider, Type serviceType, object[] serviceArgs) { // create new instance of the service: #if PocketPC var service = Activator.CreateInstance(serviceType); #else var service = CreateServiceInstance(provider, serviceType, serviceArgs); #endif if (service == null) throw new ServiceCreationException(serviceType); IServiceSite site = service as IServiceSite; // update the reference to the service provider: if (site != null) { #if PocketPC // call this function in place of constructor: site.SetSiteArguments(serviceArgs); #endif site.SetSite(provider); } return service; }
protected virtual IMonoRailContainerEx CreateDefaultMonoRailContainer(IServiceProviderEx userServiceProvider, HttpApplication appInstance) { DefaultMonoRailContainerEx container = new DefaultMonoRailContainerEx(userServiceProvider); container.UseServicesFromParent(); container.InstallPrimordialServices(); container.Configure(Configuration); FireContainerCreated(appInstance, container); if (!container.HasService <IServerUtility>()) { container.AddService <IServerUtility>(new ServerUtilityAdapter(appInstance.Context.Server)); } if (!container.HasService <IRoutingEngine>()) { container.AddService <IRoutingEngine>(RoutingModuleEx.Engine); } container.InstallMissingServices(); container.StartExtensionManager(); FireContainerInitialized(appInstance, container); return(container); }
private static object PrivateCreation(IServiceProviderEx provider, Type serviceType, object[] serviceArgs) { // create new instance of the service: #if PocketPC var service = Activator.CreateInstance(serviceType); #else var service = CreateServiceInstance(provider, serviceType, serviceArgs); #endif if (service == null) { throw new ServiceCreationException(serviceType); } IServiceSite site = service as IServiceSite; // update the reference to the service provider: if (site != null) { #if PocketPC // call this function in place of constructor: site.SetSiteArguments(serviceArgs); #endif site.SetSite(provider); } return(service); }
/// <summary> /// Init constructor. /// </summary> public ServiceTypeCloneWrapper(IServiceProviderEx provider, Type serviceType, object[] serviceConstructorArgs) : base(provider) { if (serviceType == null) throw new ArgumentNullException("serviceType"); ServiceType = serviceType; ServiceArgs = serviceConstructorArgs != null && serviceConstructorArgs.Length > 0 ? serviceConstructorArgs : null; }
/// <summary> /// Creates a new instance of the service object, if possible. /// </summary> internal static object Create(IServiceProviderEx provider, Type serviceType, object[] serviceArgs) { if (serviceType == null) throw new ArgumentNullException("serviceType"); if (serviceType.IsAbstract || serviceType.IsInterface) return null; return PrivateCreation(provider, serviceType, serviceArgs); }
/// <summary> /// Init constructor. /// </summary> public ServiceTypeCloneWrapper(IServiceProviderEx provider, Type serviceType, object[] serviceConstructorArgs) : base(provider) { if (serviceType == null) { throw new ArgumentNullException("serviceType"); } ServiceType = serviceType; ServiceArgs = serviceConstructorArgs != null && serviceConstructorArgs.Length > 0 ? serviceConstructorArgs : null; }
/// <summary> /// Init constructor. /// </summary> public ServiceDelegateCloneWrapper(IServiceProviderEx provider, object registeredServiceID, IEnumerable<Type> validators, ServiceCreationHandler serviceHandler, object[] serviceConstructorArgs) : base(provider) { if (serviceHandler == null) throw new ArgumentNullException("serviceHandler"); RegisteredServiceID = registeredServiceID; Validators = validators; ServiceHandler = serviceHandler; ServiceArgs = serviceConstructorArgs; }
/// <summary> /// Init constructor. /// </summary> public ServiceDelegateCloneWrapper(IServiceProviderEx provider, object registeredServiceID, IEnumerable <Type> validators, ServiceCreationHandler serviceHandler, object[] serviceConstructorArgs) : base(provider) { if (serviceHandler == null) { throw new ArgumentNullException("serviceHandler"); } RegisteredServiceID = registeredServiceID; Validators = validators; ServiceHandler = serviceHandler; ServiceArgs = serviceConstructorArgs; }
/// <summary> /// Init constructor. /// </summary> public ServiceObjectWrapper(IServiceProviderEx provider, object service) { if (service == null) throw new ArgumentNullException("service"); Provider = provider; Service = service; IServiceSite site = service as IServiceSite; // update the provider also for a given service: if (site != null) site.SetSite(provider); }
/// <summary> /// Creates a new instance of the service object, if possible. /// </summary> internal static object Create(IServiceProviderEx provider, Type serviceType, object[] serviceArgs) { if (serviceType == null) { throw new ArgumentNullException("serviceType"); } if (serviceType.IsAbstract || serviceType.IsInterface) { return(null); } return(PrivateCreation(provider, serviceType, serviceArgs)); }
/// <summary> /// Init constructor. /// </summary> public ServiceObjectWrapper(IServiceProviderEx provider, object service) { if (service == null) { throw new ArgumentNullException("service"); } Provider = provider; Service = service; IServiceSite site = service as IServiceSite; // update the provider also for a given service: if (site != null) { site.SetSite(provider); } }
void PerformOneTimeInitializationIfNecessary(HttpContext context) { _Locker.AcquireReaderLock(-1); if (_MonoRailContainer != null) { _Locker.ReleaseReaderLock(); } else { _Locker.UpgradeToWriterLock(-1); if (_MonoRailContainer != null) { _Locker.ReleaseWriterLock(); } else { try { if (_Configuration == null) { _Configuration = ObtainConfiguration(context.ApplicationInstance); } IServiceProviderEx userServiceProvider = _ServiceProviderLocator.LocateProvider(); _MonoRailContainer = CreateDefaultMonoRailContainer( userServiceProvider, context.ApplicationInstance); } finally { _Locker.ReleaseWriterLock(); } } } }
public void SetSite(IServiceProviderEx provider) { Provider = provider; }
/// <summary> /// Init constructor. /// </summary> public ServiceDelegateWrapper(IServiceProviderEx provider, object registeredServiceID, IEnumerable <Type> validators, ServiceCreationHandler serviceHandler, object[] serviceConstructorArgs) : base(provider, registeredServiceID, validators, serviceHandler, serviceConstructorArgs) { }
/// <summary> /// Init constructor. /// </summary> public ServiceTypeWrapper(IServiceProviderEx provider, Type serviceType, object[] serviceConstructorArgs) : base(provider, serviceType, serviceConstructorArgs) { }
/// <summary> /// Init constructor. /// </summary> protected ServiceObjectWrapper(IServiceProviderEx provider) { Provider = provider; }
/// <summary> /// Creates the default service container. /// </summary> /// <param name="userServiceProvider">The user service provider.</param> /// <param name="appInstance">The app instance.</param> /// <returns></returns> protected virtual IMonoRailContainer CreateDefaultMonoRailContainer(IServiceProviderEx userServiceProvider, HttpApplication appInstance) { var container = new DefaultMonoRailContainer(userServiceProvider); container.UseServicesFromParent(); container.InstallPrimordialServices(); container.Configure(Configuration); FireContainerCreated(appInstance, container); // Too dependent on Http and MR surroundings services to be moved to Container class if (!container.HasService<IServerUtility>()) { container.AddService<IServerUtility>(new ServerUtilityAdapter(appInstance.Context.Server)); } if (!container.HasService<IRoutingEngine>()) { container.AddService<IRoutingEngine>(RoutingModuleEx.Engine); } container.InstallMissingServices(); container.StartExtensionManager(); FireContainerInitialized(appInstance, container); return container; }
private static object CreateServiceInstance(IServiceProviderEx provider, Type serviceType, object[] serviceArgs) { #if WINDOWS_STORE || WINDOWS_APP // if arguments were specified directly, simply create new object: if (serviceArgs != null) return Activator.CreateInstance(serviceType, serviceArgs); // or loop till find first constructor, for which it was possible to create all required arguments: foreach (var method in serviceType.GetTypeInfo().DeclaredConstructors) { var paramTypes = method.GetParameters(); var paramValues = new object[paramTypes.Length]; bool failedToInitialize = false; for (int i = 0; i < paramTypes.Length && !failedToInitialize; i++) { // get the service for specified argument's type (what returns null on failure): paramValues[i] = provider.GetService(paramTypes[i].ParameterType); failedToInitialize = paramValues[i] == null; } if (failedToInitialize) continue; return method.Invoke(paramValues); } // notify, that it was impossible to initialize the required service throw new ServiceCreationException(serviceType); #else // if arguments specified directly, simply create new object: if (serviceArgs != null) return Activator.CreateInstance(serviceType, serviceArgs); // or loop till find first constructor, for which it was possible to create all required arguments: foreach (var method in serviceType.GetConstructors()) { var paramTypes = method.GetParameters(); var paramValues = new object[paramTypes.Length]; bool failedToInitialize = false; for (int i = 0; i < paramTypes.Length && !failedToInitialize; i++) { // get the service for specified argument's type (what returns null on failure): paramValues[i] = provider.GetService(paramTypes[i].ParameterType); failedToInitialize = paramValues[i] == null; } if (failedToInitialize) continue; return method.Invoke(paramValues); } // notify, that it was impossible to initialize the required service throw new ServiceCreationException(serviceType); #endif }
/// <summary> /// Init constructor. /// </summary> protected ServiceObjectWrapper (IServiceProviderEx provider) { Provider = provider; }
private static object CreateServiceInstance(IServiceProviderEx provider, Type serviceType, object[] serviceArgs) { #if WINDOWS_STORE || WINDOWS_APP // if arguments were specified directly, simply create new object: if (serviceArgs != null) { return(Activator.CreateInstance(serviceType, serviceArgs)); } // or loop till find first constructor, for which it was possible to create all required arguments: foreach (var method in serviceType.GetTypeInfo().DeclaredConstructors) { var paramTypes = method.GetParameters(); var paramValues = new object[paramTypes.Length]; bool failedToInitialize = false; for (int i = 0; i < paramTypes.Length && !failedToInitialize; i++) { // get the service for specified argument's type (what returns null on failure): paramValues[i] = provider.GetService(paramTypes[i].ParameterType); failedToInitialize = paramValues[i] == null; } if (failedToInitialize) { continue; } return(method.Invoke(paramValues)); } // notify, that it was impossible to initialize the required service throw new ServiceCreationException(serviceType); #else // if arguments specified directly, simply create new object: if (serviceArgs != null) { return(Activator.CreateInstance(serviceType, serviceArgs)); } // or loop till find first constructor, for which it was possible to create all required arguments: foreach (var method in serviceType.GetConstructors()) { var paramTypes = method.GetParameters(); var paramValues = new object[paramTypes.Length]; bool failedToInitialize = false; for (int i = 0; i < paramTypes.Length && !failedToInitialize; i++) { // get the service for specified argument's type (what returns null on failure): paramValues[i] = provider.GetService(paramTypes[i].ParameterType); failedToInitialize = paramValues[i] == null; } if (failedToInitialize) { continue; } return(method.Invoke(paramValues)); } // notify, that it was impossible to initialize the required service throw new ServiceCreationException(serviceType); #endif }