/// <summary> /// Initialize App Core Structure /// </summary> /// <param name="mvvmConfig">Mvvm configurations</param> public static async Task Init(MvvmConfig mvvmConfig = null) { IocService.Init(); RegisterServices(mvvmConfig); if (mvvmConfig?.Mappings != null) { await RunApp(mvvmConfig); } }
public IActionResult UpdateUser([FromBody] UserRequest userRequest) { IContainer container = IocService.BeginRequest(); ServiceResult <Guid> result = container.GetInstance <IUserService>().UpdateUser(userRequest); IocService.EndRequest(container); if (result.ResultType == ResultType.Error) { return(BadRequest(result.Message)); } return(Ok(result)); }
public IActionResult GetPeriods(Guid employeeId, Guid schoolId, DateTime startDateTime, DateTime endDateTime) { IContainer container = IocService.BeginRequest(); ServiceResult <List <PeriodDto> > result = container.GetInstance <IPeriodService>().GetPeriods(employeeId, schoolId, startDateTime, endDateTime); IocService.EndRequest(container); if (result.ResultType == ResultType.Error) { return(BadRequest(result.Message)); } return(Ok(result)); }
public IActionResult RemoveHomework(Guid homeworkId) { IContainer container = IocService.BeginRequest(); ServiceResult <HomeworkDto> result = container.GetInstance <IHomeworkService>().RemoveHomework(homeworkId); IocService.EndRequest(container); if (result.ResultType == ResultType.Error) { return(BadRequest(result.Message)); } return(Ok(result)); }
public IActionResult UpdateHomework([FromBody] HomeworkRequest homeworkRequest) { IContainer container = IocService.BeginRequest(); ServiceResult <HomeworkDto> result = container.GetInstance <IHomeworkService>().UpdateHomework(homeworkRequest); IocService.EndRequest(container); if (result.ResultType == ResultType.Error) { return(BadRequest(result.Message)); } return(Ok(result)); }
public IActionResult GetUserSession(string username) { IContainer container = IocService.BeginRequest(); ServiceResult <UserSessionDto> result = container.GetInstance <IUserService>().GetUserSession(username); IocService.EndRequest(container); if (result.ResultType == ResultType.Error) { return(BadRequest(result.Message)); } return(Ok(result)); }
public IActionResult GetAlexaUsersForDevice(string deviceId) { IContainer container = IocService.BeginRequest(); ServiceResult <List <AlexaUserDto> > result = container.GetInstance <IUserService>().GetAlexaUsersForDevice(deviceId); IocService.EndRequest(container); if (result.ResultType == ResultType.Error) { return(BadRequest(result.Message)); } return(Ok(result)); }
public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddDbContext <CustomerHubDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); var config = new AutoMapper.MapperConfiguration(cfg => { cfg.AddProfile(new DtoToDomainProfile()); cfg.AddProfile(new DomainToDtoProfile()); }); var mapper = config.CreateMapper(); services.AddSingleton(mapper); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = "CustomerHub", ValidAudience = "CustomerHub", IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["SecurityKey"])) }; options.Events = new JwtBearerEvents { OnAuthenticationFailed = context => { Console.WriteLine($"Invalid Token: {context.Exception.Message}"); return(Task.CompletedTask); }, OnTokenValidated = context => { Console.WriteLine($"Token OK: {context.SecurityToken}"); return(Task.CompletedTask); } }; }); services.AddOData(); IocService.Register(services); }
public ActionResult IocTest() { ViewBag.Message = "Your IocTest page."; UserInfo userInfo = IocService.GetObject("UserInfo") as UserInfo; if (userInfo != null) { ViewBag.Message = "Your IocTest page.userInfo Is Not NULL"; } else { ViewBag.Message = "Your IocTest page.userInfo Is NULL"; } return(View()); }
public void ConfigureServices(IServiceCollection services) { services.AddDbContext <TasklistDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddOData(); services.AddControllers(mvcOptions => mvcOptions.EnableEndpointRouting = false); services.AddMvc().AddFluentValidation(); IocService.Register(services); IocDomain.Register(services); ConfigureMappingService(services); ConfigureAuthenticationService(services); ConfigureSwaggerService(services); }
public IActionResult GetPastHomework(Guid schoolId, Guid employeeId, Guid subjectId, Guid studentGroupId) { IContainer container = IocService.BeginRequest(); Expression <Func <HomeworkDto, object> >[] includes = new Expression <Func <HomeworkDto, object> >[] { include => include.Students }; ServiceResult <List <HomeworkDto> > result = container.GetInstance <IHomeworkService>().GetPastHomework(schoolId, employeeId, subjectId, studentGroupId, includes); IocService.EndRequest(container); if (result.ResultType == ResultType.Error) { return(BadRequest(result.Message)); } return(Ok(result)); }
public IActionResult GetHomeworkForLesson(Guid lessonId) { IContainer container = IocService.BeginRequest(); Expression <Func <HomeworkDto, object> >[] includes = new Expression <Func <HomeworkDto, object> >[] { include => include.Resources }; ServiceResult <List <HomeworkDto> > result = container.GetInstance <IHomeworkService>().GetHomeworkForLesson(lessonId, includes); IocService.EndRequest(container); if (result.ResultType == ResultType.Error) { return(BadRequest(result.Message)); } return(Ok(result)); }
private static void RegisterServices(MvvmConfig mvvmConfig = null) { IocService.RegisterService <IMessagingCenter, MessagingCenter>(); IocService.RegisterService <INavigationService, NavigationService>(); }
/// <summary> /// Resolve an intance of your interface from DI service /// </summary> /// <typeparam name="T">interface</typeparam> /// <returns>implementation</returns> public static T ResolveViewModel <T>() where T : class, new() { return(IocService.ResolveType <T>(typeof(T))); }
/// <summary> /// Resolve an intance of your interface from DI service /// </summary> /// <typeparam name="T">interface</typeparam> /// <returns>implementation</returns> public static T ResolveService <T>() { return(IocService.ResolveService <T>()); }
/// <summary> /// Register Your Service in DI /// </summary> /// <typeparam name="TInterface">interface</typeparam> /// <typeparam name="T">implementation</typeparam> public static void RegisterService <TInterface, T>() where T : TInterface { IocService.RegisterService <TInterface, T>(); }
private static async Task RunApp(MvvmConfig mvvmConfig) { var nav = IocService.ResolveService <INavigationService>(); await nav.InitializeAsync(mvvmConfig.MainWindow, mvvmConfig.Mappings); }