Example #1
0
        private static void RegisterDependencies(HttpConfiguration config)
        {
            ContainerBuilder builder         = new ContainerBuilder();
            ApiClientContext apiClientContex = ApiClientContext.Create(cfg =>
                                                                       cfg.ConnectTo("http://localhost:18132")
                                                                       .SetCredentialsFromAppSetting("Api:UserName", "Api:Password"));

            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            builder.Register(c => apiClientContex.GetCarsClient()).As <ICarsClient>().InstancePerApiRequest();
            config.DependencyResolver = new AutofacWebApiDependencyResolver(builder.Build());
        }
Example #2
0
        private static IContainer RegisterServices(ContainerBuilder builder)
        {
            builder.RegisterControllers(typeof(MvcApplication).Assembly);

            ApiClientContext apiClientContex =
                ApiClientContext.Create(cfg =>
                                        cfg.SetCredentialsFromAppSetting(
                                            "Api:AffiliateKey", "Api:Username", "Api:Password")
                                        .ConnectTo("https://localhost:44306"));

            // Register the clients
            builder.Register(c => apiClientContex.GetShipmentsClient())
            .As <IShipmentsClient>().InstancePerHttpRequest();

            builder.Register(c => apiClientContex.GetShipmentTypesClient())
            .As <IShipmentTypesClient>().InstancePerHttpRequest();

            return(builder.Build());
        }