コード例 #1
0
        /// <summary>
        /// Autofac configuration.
        /// </summary>
        public static ContainerBuilder ConfigureContainer(
            IConfiguration configuration)
        {
            var serviceInfo = new ServiceInfo();
            var config      = new Config(configuration);
            var builder     = new ContainerBuilder();

            builder.RegisterInstance(serviceInfo)
            .AsImplementedInterfaces();

            // Register configuration interfaces
            builder.RegisterInstance(config)
            .AsImplementedInterfaces();
            builder.RegisterInstance(config.Configuration)
            .AsImplementedInterfaces();

            // Add diagnostics
            builder.AddDiagnostics(config);

            // Register http client module
            builder.RegisterModule <HttpClientModule>();
#if DEBUG
            builder.RegisterType <NoOpCertValidator>()
            .AsImplementedInterfaces();
#endif
            // Add serializers
            builder.RegisterModule <NewtonSoftJsonModule>();

            // Add unattended authentication
            builder.RegisterModule <UnattendedAuthentication>();

            // Event processor services for onboarding consumer
            builder.RegisterType <EventProcessorHost>()
            .AsImplementedInterfaces().SingleInstance();
            builder.RegisterType <EventProcessorFactory>()
            .AsImplementedInterfaces();

            // Handle iot hub telemetry events...
            builder.RegisterType <IoTHubServiceHttpClient>()
            .AsImplementedInterfaces();
            builder.RegisterType <IoTHubDeviceEventHandler>()
            .AsImplementedInterfaces();
            // ... and pass to the following handlers:

            // 1.) Handler for discovery progress
            builder.RegisterType <DiscoveryProgressHandler>()
            .AsImplementedInterfaces();
            builder.RegisterType <DiscoveryProgressEventBusPublisher>()
            .AsImplementedInterfaces();

            // 2.) Handlers for twin and device change events ...
            builder.RegisterModule <RegistryTwinEventHandlers>();

            // ... publish received events to registered event bus
            builder.RegisterType <EventBusHost>()
            .AsImplementedInterfaces().SingleInstance();
            builder.RegisterType <ServiceBusClientFactory>()
            .AsImplementedInterfaces();
            builder.RegisterType <ServiceBusEventBus>()
            .AsImplementedInterfaces().SingleInstance();

            // ... and auto start
            builder.RegisterType <HostAutoStart>()
            .AutoActivate()
            .AsImplementedInterfaces().SingleInstance();
            return(builder);
        }
コード例 #2
0
        /// <summary>
        /// Autofac configuration.
        /// </summary>
        public static ContainerBuilder ConfigureContainer(
            IConfiguration configuration)
        {
            var serviceInfo = new ServiceInfo();
            var config      = new Config(configuration);
            var builder     = new ContainerBuilder();

            builder.RegisterInstance(serviceInfo)
            .AsImplementedInterfaces().SingleInstance();

            // Register configuration interfaces
            builder.RegisterInstance(config)
            .AsImplementedInterfaces().SingleInstance();
            builder.RegisterInstance(config.Configuration)
            .AsImplementedInterfaces().SingleInstance();

            // register diagnostics
            builder.AddDiagnostics(config);

            // Event processor services for onboarding consumer
            builder.RegisterType <EventProcessorHost>()
            .AsImplementedInterfaces().SingleInstance();
            builder.RegisterType <EventProcessorFactory>()
            .AsImplementedInterfaces().SingleInstance();
            // ... and auto start
            builder.RegisterType <HostAutoStart>()
            .AutoActivate()
            .AsImplementedInterfaces().SingleInstance();

            // Handle telemetry events
            builder.RegisterType <IoTHubDeviceEventHandler>()
            .AsImplementedInterfaces().SingleInstance();

            // Handle discovery events
            builder.RegisterType <DiscoveryEventHandler>()
            .AsImplementedInterfaces().SingleInstance();
            // ... requires the corresponding services

            // Register http client module (needed for api)
            builder.RegisterModule <HttpClientModule>();
            // Use device code token provider to get tokens
            builder.RegisterType <AppAuthenticationProvider>()
            .AsImplementedInterfaces().SingleInstance();
            builder.RegisterType <OnboardingAdapter>()
            .AsImplementedInterfaces().SingleInstance();
            builder.RegisterType <OnboardingServiceClient>()
            .AsImplementedInterfaces().SingleInstance();

            // Handle discovery messages
            builder.RegisterType <DiscoveryMessageHandler>()
            .AsImplementedInterfaces().SingleInstance();

            // ... forward progress directly to clients
            builder.RegisterType <DiscoveryProgressPublisher>()
            .AsImplementedInterfaces().SingleInstance();
            builder.RegisterType <SignalRServiceHost>()
            .AsImplementedInterfaces().SingleInstance();

            // Handle twin events
            // ...

            return(builder);
        }