Пример #1
0
        /// <summary>
        /// Determines whether or not a factory exists in storage.
        /// </summary>
        /// <param name="storage">The <see cref="IFactoryStorage"/> object that holds the target factory.</param>
        /// <param name="serviceName">The name that will be associated with the target factory.</param>
        /// <param name="serviceType">The service type that the factory will be able to create.</param>
        /// <param name="additionalParameterTypes">The list of additional parameters that this factory type will support.</param>
        /// <returns>Returns <c>true</c> if the factory exists; otherwise, it will return <c>false</c>.</returns>
        public static bool ContainsFactory(this IFactoryStorage storage, string serviceName, Type serviceType,
                                           IEnumerable <Type> additionalParameterTypes)
        {
            var info = new ServiceInfo(serviceName, serviceType, additionalParameterTypes);

            return(storage.ContainsFactory(info));
        }
Пример #2
0
        /// <summary>
        /// Adds a factory to the current <see cref="IFactoryStorage"/> instance.
        /// </summary>
        /// <param name="storage">The <see cref="IFactoryStorage"/> object that will store the target factory.</param>
        /// <param name="serviceName">The name that will be associated with the target factory.</param>
        /// <param name="serviceType">The service type that the factory will be able to create.</param>
        /// <param name="additionalParameterTypes">The list of additional parameters that this factory type will support.</param>
        /// <param name="factory">The <see cref="IFactory"/> instance that will create the object instance.</param>
        public static void AddFactory(this IFactoryStorage storage, string serviceName,
                                      Type serviceType, IEnumerable <Type> additionalParameterTypes, IFactory factory)
        {
            var info = new ServiceInfo(serviceName, serviceType, additionalParameterTypes);

            storage.AddFactory(info, factory);
        }
Пример #3
0
        /// <summary>
        /// Determines which factories should be used
        /// for a particular service request.
        /// </summary>
        /// <param name="storage">The <see cref="IFactoryStorage"/> object that holds the target factory.</param>
        /// <param name="serviceName">The name that will be associated with the target factory.</param>
        /// <param name="serviceType">The service type that the factory will be able to create.</param>
        /// <param name="additionalParameters">The list of additional parameter values that this factory type will use to instantiate the service.</param>
        /// <returns>A factory instance.</returns>
        public static IFactory GetFactory(this IFactoryStorage storage, string serviceName, Type serviceType,
                                          IEnumerable <object> additionalParameters)
        {
            var additionalParameterTypes = from arg in additionalParameters
                                           let argType = arg != null?arg.GetType() : typeof(object)
                                                             select argType;

            var info = new ServiceInfo(serviceName, serviceType, additionalParameterTypes);

            return(storage.GetFactory(info));
        }
Пример #4
0
        /// <summary>
        /// Initializes the container with a custom <see cref="ICreateInstance"/> type.
        /// </summary>
        /// <param name="getServiceBehavior">The instance that will be responsible for generating service instances.</param>
        /// <param name="factoryStorage">The <see cref="IFactoryStorage"/> instance responsible for determining which factory instance will instantiate a given service request.</param>
        public ServiceContainer(IGetService getServiceBehavior, IFactoryStorage factoryStorage)
        {
            if (getServiceBehavior == null)
                throw new ArgumentNullException("getServiceBehavior");

            if (factoryStorage == null)
                throw new ArgumentNullException("factoryStorage");

            _getServiceBehavior = getServiceBehavior;
            _factoryStorage = factoryStorage;

            this.AddDefaultServices();
        }
Пример #5
0
        /// <summary>
        ///     Initializes the container with a custom <see cref="ICreateInstance" /> type.
        /// </summary>
        /// <param name="getServiceBehavior">The instance that will be responsible for generating service instances.</param>
        /// <param name="factoryStorage">
        ///     The <see cref="IFactoryStorage" /> instance responsible for determining which factory
        ///     instance will instantiate a given service request.
        /// </param>
        public ServiceContainer(IGetService getServiceBehavior, IFactoryStorage factoryStorage)
        {
            if (getServiceBehavior == null)
            {
                throw new ArgumentNullException("getServiceBehavior");
            }

            if (factoryStorage == null)
            {
                throw new ArgumentNullException("factoryStorage");
            }

            _getServiceBehavior = getServiceBehavior;
            FactoryStorage      = factoryStorage;

            this.AddDefaultServices();
        }
Пример #6
0
 public override void Term()
 {
     _storage = null;
 }
Пример #7
0
 public override void Init()
 {
     _storage = new FactoryStorage();
 }
Пример #8
0
 public override void Term()
 {
     _storage = null;
 }
Пример #9
0
 public override void Init()
 {
     _storage = new FactoryStorage();
 }