static void Main(string[] args) { IContainer container; // use reflection registration //ContainerBuilder builder = new ContainerBuilder(); //string[] assemblyScanerPattern = new[] { @"AutofacModules.*.dll" }; //// Make sure process paths are sane... //Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory); //// Scan for assemblies containing autofac modules in the bin folder //List<Assembly> assemblies = new List<Assembly>(); //assemblies.AddRange( // Directory.EnumerateFiles(Directory.GetCurrentDirectory(), "AutofacModules.*.dll", SearchOption.AllDirectories) // .Where(filename => assemblyScanerPattern.Any(pattern => Regex.IsMatch(filename, pattern))) // .Select(Assembly.LoadFrom) // ); //// register the types //foreach (var assembly in assemblies) //{ // builder.RegisterAssemblyTypes(assembly) // .AsImplementedInterfaces(); //} //container = builder.Build(); //var proj = container.Resolve<IShoppingCartRepository>(); //proj.Create(new ShoppingCartItem() { userId = 99, product = "laptop" }); // end container = RegistrationModule.BuildContainer(); var shoppingCartRepository = container.Resolve <IShoppingCartRepository>(); shoppingCartRepository.Create(new ShoppingCartItem { userId = 1, product = "laptop" }); Console.Read(); }
public static void RegisterServices(IServiceCollection services) { //this should be singleton through application services.AddSingleton <IMongoDbClient, MongoDbClient>(); services.AddSingleton <IExchangeRefreshTokenUseCase, ExchangeRefreshTokenUseCase>(); services.AddSingleton <ExchangeRefreshTokenPresenter, ExchangeRefreshTokenPresenter>(); services.AddSingleton <IJwtTokenHandler, JwtTokenHandler>(); services.AddSingleton <ILogger, Logger>(); services.AddSingleton <IJwtTokenValidator, JwtTokenValidator>(); services.AddSingleton <IJwtFactory, JwtFactory>(); services.AddSingleton <IJwtFactory, JwtFactory>(); services.AddSingleton <ITokenFactory, TokenFactory>(); services.AddSingleton <ILoginUseCase, LoginUseCase>(); services.AddSingleton <LoginPresenter, LoginPresenter>(); CustomFieldsModule.Register(services); RegistrationModule.Register(services); }
/// <summary> /// Registers a module with registrations. /// </summary> /// <param name="registrationModule">The module to register within this container builder.</param> public void RegisterModule(RegistrationModule registrationModule) { registrationModule.Register(this); }
public static void ConfigureContainer() { var container = RegistrationModule.BuildContainer(); DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); }