// From https://jasperfx.github.io/lamar/documentation/ioc/aspnetcore/ // Take in Lamar's ServiceRegistry instead of IServiceCollection // as your argument, but fear not, it implements IServiceCollection // as well public void ConfigureContainer(ServiceRegistry services) { services.AddEFSecondLevelCache(options => { options.UseMemoryCacheProvider() .CacheAllQueries(CacheExpirationMode.Absolute, TimeSpan.FromMinutes(30)); }); var connectionString = Configuration["ConnectionStrings:ApplicationDbContextConnection"]; if (connectionString.Contains("%CONTENTROOTPATH%")) { connectionString = connectionString.Replace("%CONTENTROOTPATH%", _contentRootPath); } services.AddConfiguredMsSqlDbContext(connectionString); services.AddControllersWithViews(); // Also exposes Lamar specific registrations // and functionality services.Scan(s => { s.TheCallingAssembly(); s.WithDefaultConventions(); }); }
public void ConfigureContainer(ServiceRegistry registry) { var containerConfig = ContainerConfiguration.CreateFromAssembly(typeof(Startup).Assembly); ServiceProvisioningInitializer.PopulateRegistry(containerConfig, registry); var dropboxLocator = new Container(registry).GetService <IDropboxLocator>(); var dropboxPath = dropboxLocator.LocateDropboxPath(); var completePath = Path.Combine(dropboxPath, "Apps", "LinkedInPoc", "Secrets.txt"); var textLines = File.ReadAllLines(completePath); registry.AddAuthentication( options => { options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; options.DefaultChallengeScheme = "LinkedIn"; }) .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme) .AddLinkedIn("LinkedIn", options => { options.ClientId = textLines[0]; options.ClientSecret = textLines[1]; options.CallbackPath = new PathString("/signin-linkedin"); options.SaveTokens = true; options.Scope.Clear(); options.Scope.Add("r_liteprofile"); options.Scope.Add("r_emailaddress"); options.Scope.Add("w_member_social"); options.Events.OnCreatingTicket = ticket => { // For some reason, HttpContext.GetTokenAsync("access_token") doesn't work; LinkedInAccessTokenSingleton.Value = ticket.AccessToken; return(Task.CompletedTask); }; }); registry.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer( Configuration.GetConnectionString("DefaultConnection"))); registry.AddDefaultIdentity <IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true) .AddEntityFrameworkStores <ApplicationDbContext>(); registry.AddControllersWithViews(); registry.AddRazorPages(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureContainer(ServiceRegistry services) { services.AddControllersWithViews().AddControllersAsServices().AddJsonOptions(x => { x.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); x.JsonSerializerOptions.MaxDepth = 255; }); // In production, the Angular files will be served from this directory services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/dist"; }); services.AddEntityFrameworkSqlServer(); services.AddSwaggerGen(c => { c.AddServer(new OpenApiServer { Url = "http://localhost:5000", Description = "HTTP endpoint" }); c.AddServer(new OpenApiServer { Url = "https://localhost:5001", Description = "HTTP endpoint with SSL" }); c.SwaggerDoc("v1", new OpenApiInfo { Title = "Where Is My Fleet API", Version = "v1" }); c.CustomSchemaIds((t) => { return(t.FullName.Replace("+", "")); }); }); //var applicationServicesAssembly = Assembly.Load(); services.AddMediatR(typeof(WhereIsMyFleet.Services.CurrentUserModel).Assembly); services.For <IConfiguration>().Use(Configuration); services.AddDbContext <WhereIsMyFleetDbContext>(o => o.UseSqlServer(Configuration.GetConnectionString("WhereIsMyFleet"))); services.SetupRegistries(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureContainer(ServiceRegistry services) { services.AddCors(options => { options.AddPolicy(name: AllowDevCors, builder => { builder.WithOrigins("http://localhost:3000"); }); }); services.AddControllersWithViews(); services.IncludeRegistry <WebRegistry>(); services.AddHostedService <RabbitService>(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "ConsumerModul.GitLab - NextPipe Module - Beta API", Version = "v1" }); }); services.AddSpaStaticFiles(conf => { conf.RootPath = "ClientApp/build"; }); }
public void ConfigureContainer(ServiceRegistry services) { // Add your ASP.Net Core services as usual services.AddMvc(); services.AddLogging(); services.AddControllersWithViews(); // In production, the React files will be served from this directory services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/build"; }); // Also exposes Lamar specific registrations // and functionality services.Scan(scanner => { // Here you can add various assembly scans // to ensure Lamar finds all your classes // and registers your project conventions. scanner.TheCallingAssembly(); scanner.WithDefaultConventions(); scanner.SingleImplementationsOfInterface(); // Add all implementations of an interface scanner.AssemblyContainingType <IUserService>(); scanner.AssemblyContainingType <IMenuService>(); }); // You can create your own registries like with StructurMap // and use expressions to configure types //services.For<IAbstraction>().Use(new ConcreteImplementation()); // Power up your architechture with the decorator pattern //services // .For(typeof(ICommandHandler<>)) // .DecorateAllWith(typeof(ValidationCommandHandlerDecorator)); }