Exemplo n.º 1
0
        /// <summary>
        /// Application start event.
        /// </summary>
        protected void Application_Start()
        {
            // Set Application Insights instrumentation key
            var configProvider = new LocalConfigProvider();

            TelemetryConfiguration.Active.InstrumentationKey = configProvider.GetSetting(CommonConfig.ApplicationInsightsInstrumentationKey);

            Conversation.UpdateContainer(
                builder =>
            {
                builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly()));
                builder.RegisterModule(new CelebrationsAppModule());

                builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
                builder.RegisterWebApiFilterProvider(GlobalConfiguration.Configuration);

                builder.RegisterControllers(Assembly.GetExecutingAssembly());
            });

            GlobalConfiguration.Configure(WebApiConfig.Register);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            DependencyResolver.SetResolver(new AutofacDependencyResolver(Conversation.Container));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Register Autofac dependencies
        /// </summary>
        public static void RegisterDependencies()
        {
            var builder = new ContainerBuilder();

            builder.RegisterControllers(Assembly.GetExecutingAssembly());
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

            var connectionString = ConfigurationManager.AppSettings["StorageConnectionString"];

            var config = new LocalConfigProvider();

            builder.Register(c => config)
            .As <IConfigProvider>()
            .SingleInstance();

            builder.Register(c => new AppInsightsLogProvider(c.Resolve <IConfigProvider>()))
            .As <ILogProvider>()
            .SingleInstance();

            builder.Register(c => new HttpClient())
            .SingleInstance();

            builder.Register(c => new JwtHelper(
                                 jwtSecurityKey: ConfigurationManager.AppSettings["TokenEncryptionKey"],
                                 botId: ConfigurationManager.AppSettings["MicrosoftAppId"]))
            .SingleInstance();

            builder.Register(c => new KBInfoHelper(connectionString))
            .SingleInstance();

            builder.Register(c => new TokenHelper(
                                 c.Resolve <HttpClient>(),
                                 connectionString,
                                 ConfigurationManager.AppSettings["TenantId"],
                                 ConfigurationManager.AppSettings["GraphAppClientId"],
                                 ConfigurationManager.AppSettings["GraphAppClientSecret"],
                                 ConfigurationManager.AppSettings["TokenEncryptionKey"]))
            .SingleInstance();

            builder.Register(c => new GraphHelper(
                                 c.Resolve <HttpClient>(),
                                 c.Resolve <TokenHelper>()))
            .SingleInstance();

            builder.Register(c => new BlobHelper(connectionString))
            .SingleInstance();

            builder.Register(c => new QnAMakerService(
                                 c.Resolve <HttpClient>(),
                                 ConfigurationManager.AppSettings["QnaMakerApiEndpointUrl"],
                                 ConfigurationManager.AppSettings["QnAMakerSubscriptionKey"],
                                 ConfigurationManager.AppSettings["QnAMakerHostUrl"]))
            .SingleInstance();

            builder.Register(c => new KnowledgeBaseRefreshHelper(
                                 c.Resolve <BlobHelper>(),
                                 c.Resolve <KBInfoHelper>(),
                                 c.Resolve <GraphHelper>(),
                                 c.Resolve <QnAMakerService>(),
                                 c.Resolve <ILogProvider>()))
            .SingleInstance();

            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
            GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Register Autofac dependencies
        /// </summary>
        /// <returns>Autofac container</returns>
        public static IContainer RegisterDependencies()
        {
            var builder = new ContainerBuilder();

            builder.RegisterControllers(Assembly.GetExecutingAssembly());

            var config = new LocalConfigProvider();

            builder.Register(c => config)
            .As <IConfigProvider>()
            .SingleInstance();

            builder.Register(c => new AppInsightsLogProvider(c.Resolve <IConfigProvider>()))
            .As <ILogProvider>()
            .SingleInstance();

            builder.Register(c => new HttpClient())
            .SingleInstance();

            builder.Register(c => new KBInfoHelper(ConfigurationManager.AppSettings["StorageConnectionString"]))
            .SingleInstance();

            builder.Register(c => new TokenHelper(
                                 c.Resolve <HttpClient>(),
                                 ConfigurationManager.AppSettings["StorageConnectionString"],
                                 ConfigurationManager.AppSettings["ida:TenantId"],
                                 ConfigurationManager.AppSettings["GraphAppClientId"],
                                 ConfigurationManager.AppSettings["GraphAppClientSecret"],
                                 ConfigurationManager.AppSettings["TokenEncryptionKey"]))
            .SingleInstance();

            builder.Register(c => new GraphHelper(
                                 c.Resolve <HttpClient>(),
                                 c.Resolve <TokenHelper>()))
            .SingleInstance();

            builder.Register(c => new QnAMakerService(
                                 c.Resolve <HttpClient>(),
                                 ConfigurationManager.AppSettings["QnaMakerApiEndpointUrl"],
                                 ConfigurationManager.AppSettings["QnAMakerSubscriptionKey"],
                                 hostUrl: null)) // Host URL is not needed in config app
            .SingleInstance();

            builder.Register(c => new BlobHelper(
                                 ConfigurationManager.AppSettings["StorageConnectionString"]))
            .SingleInstance();

            builder.Register(c => new KnowledgeBaseRefreshHelper(
                                 c.Resolve <BlobHelper>(),
                                 c.Resolve <KBInfoHelper>(),
                                 c.Resolve <GraphHelper>(),
                                 c.Resolve <QnAMakerService>(),
                                 c.Resolve <ILogProvider>()))
            .SingleInstance();

            builder.RegisterType <HomeController>().InstancePerRequest();

            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            return(container);
        }
Exemplo n.º 4
0
        /// <inheritdoc/>
        protected override void Load(ContainerBuilder builder)
        {
            base.Load(builder);

            var configProvider = new LocalConfigProvider();

            builder.Register(c => configProvider)
            .Keyed <IConfigProvider>(FiberModule.Key_DoNotSerialize)
            .AsImplementedInterfaces()
            .SingleInstance();

            builder.Register(c =>
            {
                return(new TelemetryClient(new TelemetryConfiguration(configProvider.GetSetting(CommonConfig.ApplicationInsightsInstrumentationKey))));
            }).SingleInstance();

            builder.RegisterType <UserManagementHelper>().SingleInstance();
            builder.RegisterType <EventHelper>().SingleInstance();

            // Override some Bot Framework registrations
            builder.Register(c => c.Resolve <IConnectorClientFactory>().MakeConnectorClient())
            .Keyed <IConnectorClient>(FiberModule.Key_DoNotSerialize)    // Tag IConnectorClient as DoNotSerialize
            .As <IConnectorClient>()
            .ExternallyOwned();

            var appInsightsLogProvider = new AppInsightsLogProvider(configProvider);

            builder.Register(c => appInsightsLogProvider)
            .Keyed <ILogProvider>(FiberModule.Key_DoNotSerialize)
            .AsImplementedInterfaces()
            .SingleInstance();

            var store = new DocumentDbBotDataStore(
                new Uri(configProvider.GetSetting(ApplicationConfig.CosmosDBEndpointUrl)),
                configProvider.GetSetting(ApplicationConfig.CosmosDBKey));

            builder.Register(c => store)
            .Keyed <IBotDataStore <BotData> >(AzureModule.Key_DataStore)
            .AsSelf()
            .SingleInstance();
            builder.Register(c => new CachingBotDataStore(store, CachingBotDataStoreConsistencyPolicy.LastWriteWins))
            .As <IBotDataStore <BotData> >()
            .AsSelf()
            .InstancePerLifetimeScope();

            // Register dialogs
            builder.RegisterType <RootDialog>()
            .AsSelf()
            .InstancePerDependency();

            builder.RegisterType <DialogFactory>()
            .Keyed <DialogFactory>(FiberModule.Key_DoNotSerialize)
            .AsSelf()
            .InstancePerMatchingLifetimeScope(DialogModule.LifetimeScopeTag);

            builder.RegisterType <SkipEventDialog>()
            .AsSelf()
            .InstancePerDependency();

            builder.RegisterType <ShareEventDialog>()
            .AsSelf()
            .InstancePerDependency();

            builder.RegisterType <IgnoreEventShareDialog>()
            .AsSelf()
            .InstancePerDependency();
        }
Exemplo n.º 5
0
        /// <inheritdoc/>
        protected override void Load(ContainerBuilder builder)
        {
            base.Load(builder);

            var configProvider = new LocalConfigProvider();

            builder.Register(c => configProvider)
            .Keyed <IConfigProvider>(FiberModule.Key_DoNotSerialize)
            .AsImplementedInterfaces()
            .SingleInstance();

            builder.Register(c =>
            {
                return(new TelemetryClient(new TelemetryConfiguration(configProvider.GetSetting(CommonConfig.ApplicationInsightsInstrumentationKey))));
            }).SingleInstance();

            builder.RegisterType <UserManagementHelper>()
            .Keyed <IUserManagementHelper>(FiberModule.Key_DoNotSerialize)
            .AsImplementedInterfaces()
            .SingleInstance();
            builder.RegisterType <EventDataProvider>()
            .Keyed <IEventDataProvider>(FiberModule.Key_DoNotSerialize)
            .AsImplementedInterfaces()
            .SingleInstance();
            builder.RegisterType <Helpers.ConnectorClientFactory>()
            .Keyed <Helpers.IConnectorClientFactory>(FiberModule.Key_DoNotSerialize)
            .AsImplementedInterfaces()
            .SingleInstance();

            // Override some Bot Framework registrations
            builder.Register(c => c.Resolve <Bot.Builder.Dialogs.Internals.IConnectorClientFactory>().MakeConnectorClient())
            .Keyed <IConnectorClient>(FiberModule.Key_DoNotSerialize)    // Tag IConnectorClient as DoNotSerialize
            .As <IConnectorClient>()
            .ExternallyOwned();

            var appInsightsLogProvider = new AppInsightsLogProvider(configProvider);

            builder.Register(c => appInsightsLogProvider)
            .Keyed <ILogProvider>(FiberModule.Key_DoNotSerialize)
            .AsImplementedInterfaces()
            .SingleInstance();

            builder.Register(c => new TokenValidator(
                                 configProvider.GetSetting(CommonConfig.ActiveDirectoryClientId)))
            .AsImplementedInterfaces()
            .SingleInstance();

            // Use an in-memory store, as the bot does not currently use bot state storage.
            var store = new InMemoryDataStore();

            builder.Register(c => store)
            .As <IBotDataStore <BotData> >()
            .AsSelf()
            .SingleInstance();

            // Register dialogs
            builder.RegisterType <RootDialog>()
            .AsSelf()
            .InstancePerDependency();

            builder.RegisterType <DialogFactory>()
            .Keyed <DialogFactory>(FiberModule.Key_DoNotSerialize)
            .AsSelf()
            .InstancePerMatchingLifetimeScope(DialogModule.LifetimeScopeTag);

            builder.RegisterType <SkipEventDialog>()
            .AsSelf()
            .InstancePerDependency();

            builder.RegisterType <ShareEventDialog>()
            .AsSelf()
            .InstancePerDependency();

            builder.RegisterType <IgnoreEventShareDialog>()
            .AsSelf()
            .InstancePerDependency();
        }