コード例 #1
0
 /// <summary>
 /// Creates a <see cref="DataSourceConfigurationCreator"/>.
 /// </summary>
 /// <param name="assembly">The <see cref="DataSourceAssembly"/> to use</param>
 /// <exception cref="ArgumentNullException">If <see cref="null"/> is passed</exception>
 public DataSourceConfigurationCreator(DataSourceAssembly assembly)
 {
     if (assembly is null)
     {
         throw new ArgumentNullException(nameof(assembly));
     }
     this.assembly = assembly;
 }
コード例 #2
0
        /// <summary>
        /// Creates the Ninject bindings for a data source
        /// </summary>
        /// <typeparam name="T">The type the data source is for</typeparam>
        /// <param name="kernel">The IoC container's <see cref="IKernel"/></param>
        /// <returns>The IoC container's <see cref="IKernel"/></returns>
        /// <exception cref="InvalidDataSourceTypeException">Thrown if the data source type configured in the application settings isn't in the list of supported types</exception>
        public IKernel Bind <T>(IKernel kernel)
        {
            if (kernel is null)
            {
                throw new ArgumentNullException(nameof(kernel));
            }

            string dataSourceId   = dataSourceTypeIds[typeof(T)];
            string dataSourceType = DataSourceConfiguration.GetConfiguredType(configuration, dataSourceId);

            if (!IsDataSourceTypeValid(dataSourceType))
            {
                throw new InvalidDataSourceTypeException(dataSourceId, dataSourceType);
            }

            DataSourceAssembly             dataSourceAssembly   = new DataSourceAssembly(dataSourceType);
            DataSourceConfigurationCreator configurationCreator = new DataSourceConfigurationCreator(dataSourceAssembly);
            object config = configurationCreator.Create(configuration, dataSourceId);

            kernel.Bind(dataSourceAssembly.TypeOfConfigurationInterface).ToConstant(config).Named(typeof(T).Name);
            kernel.Load(dataSourceAssembly.UnderlyingAssembly);

            return(kernel);
        }