public void ConfigureContainer(IAppBuilder app) { ContainerBuilder builder = new ContainerBuilder(); DependencyRegistrator.RegisterModules(builder); Assembly assembly = typeof(WebApiApplication).Assembly; // WebApi HttpConfiguration config = GlobalConfiguration.Configuration; // This for OWIN integration(OWIN hosting): HttpConfiguration config = new HttpConfiguration(); builder.RegisterApiControllers(assembly); // OPTIONAL: Register the Autofac filter provider: builder.RegisterWebApiFilterProvider(config); // MVC builder.RegisterControllers(assembly); IContainer container = builder.Build(); // MVC DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); // WebApi config.DependencyResolver = new AutofacWebApiDependencyResolver(container); app.UseAutofacMiddleware(container); app.UseAutofacWebApi(config); app.UseAutofacMvc(); }
static void Main(string[] args) { var serviceProvider = DependencyRegistrator.Register(); var app = serviceProvider.GetService <IApplication>(); app.Run(); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); // Register routes new RouteRegistrator().RegisterRoutes(RouteTable.Routes); // Build DI container var dependencyRegistrator = new DependencyRegistrator(); var container = dependencyRegistrator.BuildContainer(); DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); }
protected override void InitializeFirstChance() { base.InitializeFirstChance(); Mvx.LazyConstructAndRegisterSingleton <IConnectivity, ConnectivityImplementation>(); Mvx.LazyConstructAndRegisterSingleton <IDialogService, DialogService>(); Mvx.LazyConstructAndRegisterSingleton <IOneDriveAuthenticator, OneDriveAuthenticator>(); Mvx.LazyConstructAndRegisterSingleton <IProtectedData, ProtectedData>(); Mvx.LazyConstructAndRegisterSingleton <ITileManager, TileManager>(); Mvx.LazyConstructAndRegisterSingleton <IAppInformation, AppInformation>(); Mvx.LazyConstructAndRegisterSingleton <IStoreOperations, StoreOperations>(); Mvx.LazyConstructAndRegisterSingleton <ISettings, Settings>(); Mvx.LazyConstructAndRegisterSingleton <IBackgroundTaskManager, BackgroundTaskManager>(); DependencyRegistrator.RegisterDependencies(); }
private void RegisterDependencies(ContainerBuilder builder) { DependencyRegistrator.RegisterModules(builder); }