Exemplo n.º 1
0
        /// <summary>
        /// Gets an instance of the specified service.
        /// </summary>
        /// <param name="serviceTemplate">The service template.</param>
        /// <param name="config">The configuration.</param>
        /// <returns>A service instance.</returns>
        internal TService GetService <TService, TServiceSetting>(
            ServiceTemplate <TService, TServiceSetting> serviceTemplate, GoogleAdsConfig config)
            where TServiceSetting : ServiceSettingsBase, new()
            where TService : GoogleAdsServiceClientBase
        {
            Channel     channel     = CreateChannel(config);
            CallInvoker callInvoker = channel.Intercept(
                LoggingInterceptor.GetInstance(config));

            // Build a service context to bind the service, configuration and CallSettings.
            GoogleAdsServiceContext serviceContext = new GoogleAdsServiceContext();

            // Build the call settings.
            CallSettings callSettings = CreateCallSettings <TServiceSetting>(config,
                                                                             serviceContext);

            serviceContext.CallSettings = callSettings;

            // Create the service settings.
            TServiceSetting serviceSettings = CreateServiceSettings <TServiceSetting>(
                serviceContext);

            // Create the service.
            TService service = Create(serviceTemplate, callInvoker, serviceSettings);

            serviceContext.Service = service;
            service.ServiceContext = serviceContext;
            return(service);
        }
        /// <summary>
        /// Gets an instance of the specified service.
        /// </summary>
        /// <param name="serviceTemplate">The service template.</param>
        /// <param name="config">The configuration.</param>
        /// <returns>A service instance.</returns>
        internal TService GetService <TService, TServiceSetting>(
            ServiceTemplate <TService, TServiceSetting> serviceTemplate, GoogleAdsConfig config)
            where TServiceSetting : ServiceSettingsBase, new()
            where TService : GoogleAdsServiceClientBase
        {
            Channel     channel     = CreateChannel(config);
            CallInvoker callInvoker = channel.Intercept(
                LoggingInterceptor.GetInstance(config));

            GoogleAdsServiceContext serviceContext  = CreateServiceContext(config);
            TServiceSetting         serviceSettings = CreateServiceSettings <TServiceSetting>(
                serviceContext);
            TService service = Create <TService, TServiceSetting>(
                callInvoker, serviceSettings);

            serviceContext.Service = service;
            service.ServiceContext = serviceContext;
            return(service);
        }