/// <summary>
 /// Init constructor.
 /// </summary>
 public ServiceCreationEventArgs(IServiceProviderEx provider, object registeredServiceID, object requestedServiceID, object[] serviceArgs)
 {
     Provider = provider;
     RegisteredServiceID = registeredServiceID;
     RequestedServiceID = requestedServiceID;
     ServiceArgs = serviceArgs;
 }
 /// <summary>
 /// Init constructor.
 /// </summary>
 public ServiceCreationEventArgs(IServiceProviderEx provider, object registeredServiceID, object requestedServiceID, object[] serviceArgs)
 {
     Provider            = provider;
     RegisteredServiceID = registeredServiceID;
     RequestedServiceID  = requestedServiceID;
     ServiceArgs         = serviceArgs;
 }
Exemplo n.º 3
0
        /// <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;
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 9
0
        /// <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;
        }
Exemplo n.º 12
0
        /// <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);
        }
Exemplo n.º 13
0
        /// <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));
        }
Exemplo n.º 14
0
        /// <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);
            }
        }
Exemplo n.º 15
0
        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();
                    }
                }
            }
        }
Exemplo n.º 16
0
 public void SetSite(IServiceProviderEx provider)
 {
     Provider = provider;
 }
Exemplo n.º 17
0
 /// <summary>
 /// Init constructor.
 /// </summary>
 public ServiceDelegateWrapper(IServiceProviderEx provider, object registeredServiceID, IEnumerable <Type> validators, ServiceCreationHandler serviceHandler, object[] serviceConstructorArgs)
     : base(provider, registeredServiceID, validators, serviceHandler, serviceConstructorArgs)
 {
 }
Exemplo n.º 18
0
 /// <summary>
 /// Init constructor.
 /// </summary>
 public ServiceTypeWrapper(IServiceProviderEx provider, Type serviceType, object[] serviceConstructorArgs)
     : base(provider, serviceType, serviceConstructorArgs)
 {
 }
Exemplo n.º 19
0
 /// <summary>
 /// Init constructor.
 /// </summary>
 protected ServiceObjectWrapper(IServiceProviderEx provider)
 {
     Provider = provider;
 }
Exemplo n.º 20
0
 public void SetSite(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
        }
Exemplo n.º 23
0
 /// <summary>
 /// Init constructor.
 /// </summary>
 public ServiceTypeWrapper(IServiceProviderEx provider, Type serviceType, object[] serviceConstructorArgs)
     : base(provider, serviceType, serviceConstructorArgs)
 {
 }
Exemplo n.º 24
0
 /// <summary>
 /// Init constructor.
 /// </summary>
 protected ServiceObjectWrapper (IServiceProviderEx provider)
 {
     Provider = provider;
 }
Exemplo n.º 25
0
        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
        }