public void TransientInSingleton() { ServiceContainer services = new ServiceContainer(); services.AddSingleton <IParentService, ParentService>(); services.AddTransient <IFirstChildService, FirstChildService>(); services.AddTransient <ISecondChildService, SecondChildService>(); IParentService parent = services.Get <IParentService>(); parent.Foo = "parent"; parent.First.Foo = "first"; parent.Second.Foo = "second"; //services in singleton service is created only once (cuz they created via parent) IParentService p = services.Get <IParentService>(); Assert.Equal(parent.Foo, p.Foo); Assert.Equal(parent.First.Foo, p.First.Foo); Assert.Equal(parent.Second.Foo, p.Second.Foo); IFirstChildService first = services.Get <IFirstChildService>(); Assert.NotEqual(parent.First.Foo, first.Foo); ISecondChildService second = services.Get <ISecondChildService>(); Assert.NotEqual(parent.Second.Foo, second.Foo); }
public void SingletonInTransient() { ServiceContainer services = new ServiceContainer(); services.AddTransient <IParentService, ParentService>(); services.AddSingleton <IFirstChildService, FirstChildService>(); services.AddSingleton <ISecondChildService, SecondChildService>(); IFirstChildService first = services.Get <IFirstChildService>(); first.Foo = "first"; IParentService parent = services.Get <IParentService>(); parent.Foo = "parent"; parent.Second.Foo = "second"; Assert.Equal(first.Foo, parent.First.Foo); ISecondChildService second = services.Get <ISecondChildService>(); Assert.Equal(second.Foo, parent.Second.Foo); IParentService p = services.Get <IParentService>(); Assert.NotEqual(p.Foo, parent.Foo); Assert.Equal(p.First.Foo, parent.First.Foo); Assert.Equal(p.Second.Foo, parent.Second.Foo); }
public void ScopedInTransient() { ServiceContainer services = new ServiceContainer(); services.AddTransient <IParentService, ParentService>(); services.AddScoped <IFirstChildService, FirstChildService>(); services.AddScoped <ISecondChildService, SecondChildService>(); Assert.Throws <ScopeException>(() => services.Get <IParentService>()); Assert.Throws <ScopeException>(() => services.Get <IFirstChildService>()); Assert.Throws <ScopeException>(() => services.Get <ISecondChildService>()); IContainerScope scope = services.CreateScope(); IParentService parent = services.Get <IParentService>(scope); parent.Foo = "parent"; parent.First.Foo = "first"; parent.Second.Foo = "second"; IParentService p1 = services.Get <IParentService>(scope); Assert.NotEqual(parent.Foo, p1.Foo); Assert.Equal(parent.First.Foo, p1.First.Foo); Assert.Equal(parent.Second.Foo, p1.Second.Foo); IContainerScope scope2 = services.CreateScope(); IParentService p2 = services.Get <IParentService>(scope2); Assert.NotEqual(parent.Foo, p2.Foo); Assert.NotEqual(parent.First.Foo, p2.First.Foo); Assert.NotEqual(parent.Second.Foo, p2.Second.Foo); }
public async Task ScopedInTransientPool() { ServiceContainer services = new ServiceContainer(); services.AddTransientPool <IParentService, ParentService>(); services.AddScoped <IFirstChildService, FirstChildService>(); services.AddScoped <ISecondChildService, SecondChildService>(); IContainerScope scope = services.CreateScope(); IParentService parent = await services.Get <IParentService>(scope); parent.Foo = "parent"; parent.First.Foo = "first"; parent.Second.Foo = "second"; IParentService p = await services.Get <IParentService>(scope); Assert.NotEqual(parent.Foo, p.Foo); Assert.Equal(parent.First.Foo, p.First.Foo); Assert.Equal(parent.Second.Foo, p.Second.Foo); await Assert.ThrowsAsync <InvalidOperationException>(async() => await services.Get <IFirstChildService>()); IFirstChildService f2 = await services.Get <IFirstChildService>(scope); Assert.Equal(parent.First.Foo, f2.Foo); await Assert.ThrowsAsync <InvalidOperationException>(async() => await services.Get <ISecondChildService>()); ISecondChildService s2 = await services.Get <ISecondChildService>(scope); Assert.Equal(parent.Second.Foo, s2.Foo); }
public void TransientInTransientPool() { ServiceContainer services = new ServiceContainer(); services.AddTransientPool <IParentService, ParentService>(); services.AddTransient <IFirstChildService, FirstChildService>(); services.AddTransient <ISecondChildService, SecondChildService>(); IContainerScope scope = services.CreateScope(); IParentService parent = services.Get <IParentService>(scope); parent.Foo = "parent"; parent.First.Foo = "first"; parent.Second.Foo = "second"; IParentService p = services.Get <IParentService>(scope); Assert.NotEqual(parent.Foo, p.Foo); Assert.NotEqual(parent.First.Foo, p.First.Foo); Assert.NotEqual(parent.Second.Foo, p.Second.Foo); IFirstChildService f1 = services.Get <IFirstChildService>(); IFirstChildService f2 = services.Get <IFirstChildService>(scope); Assert.NotEqual(parent.First.Foo, f1.Foo); Assert.NotEqual(parent.First.Foo, f2.Foo); ISecondChildService s1 = services.Get <ISecondChildService>(); ISecondChildService s2 = services.Get <ISecondChildService>(scope); Assert.NotEqual(parent.Second.Foo, s1.Foo); Assert.NotEqual(parent.Second.Foo, s2.Foo); }
public HomeViewModel(IUserDialogs userDialogs, IParentService parentService, IMvxMessenger mvxMessenger, AppHelper appHelper, IAlertService alertService) : base(userDialogs, mvxMessenger, appHelper) { _parentService = parentService; _alertService = alertService; RefreshCommand = ReactiveCommand.CreateFromObservable <Unit, PageModel>((param) => { RefreshBindings(); return(Observable.Zip( _parentService.GetProfileInformation(), _parentService.GetChildren().OnErrorResumeNext(Observable.Return(new List <SonEntity>())), _alertService.GetLastAlertsForSelfParent().OnErrorResumeNext(Observable.Return(new AlertsPageEntity())), (ParentEntity, SonEntities, AlertsPageEntity) => new PageModel() { SelfParent = ParentEntity, SonEntities = SonEntities, AlertsPage = AlertsPageEntity })); }); RefreshCommand.Subscribe(OnPageModelLoadedHandler); RefreshCommand.IsExecuting.Subscribe((IsLoading) => IsBusy = IsLoading); RefreshCommand.ThrownExceptions.Subscribe(HandleExceptions); }
public async Task TransientInScoped() { ServiceContainer services = new ServiceContainer(); services.AddScoped <IParentService, ParentService>(); services.AddTransient <IFirstChildService, FirstChildService>(); services.AddTransient <ISecondChildService, SecondChildService>(); IContainerScope scope = services.CreateScope(); IParentService parent = await services.Get <IParentService>(scope); parent.Foo = "parent"; parent.First.Foo = "first"; parent.Second.Foo = "second"; //services in scoped service is created only once (cuz they created via parent) IParentService p = await services.Get <IParentService>(scope); Assert.Equal(parent.Foo, p.Foo); Assert.Equal(parent.First.Foo, p.First.Foo); Assert.Equal(parent.Second.Foo, p.Second.Foo); IFirstChildService first = await services.Get <IFirstChildService>(scope); Assert.NotEqual(parent.First.Foo, first.Foo); ISecondChildService second = await services.Get <ISecondChildService>(scope); Assert.NotEqual(parent.Second.Foo, second.Foo); }
static async Task Main(string[] args) { ServiceContainer services = new ServiceContainer(); services.AddTransient <IServiceB, ServiceB>(); services.AddTransient <IServiceC, ServiceC>(); services.AddTransient <IServiceA, ServiceA>(); services.AddTransient <IParentService, ParentService>(); ITwinoServiceProvider provider = services.GetProvider(); IContainerScope scope = provider.CreateScope(); IParentService service = services.Get <IParentService>(scope); Console.WriteLine(service); Console.ReadLine(); object s; Type t = typeof(IParentService); while (true) { Stopwatch swx = new Stopwatch(); swx.Start(); for (int i = 0; i < 10000000; i++) { s = provider.Get <IParentService>(); //scope); } swx.Stop(); Console.WriteLine("Total : " + swx.ElapsedMilliseconds); Console.ReadLine(); } }
public ParentController( IParentService parentService, ILogger <BaseController> logger ) : base(logger) { ParentService = parentService; }
public StudentController(IStudentService studentService, IParentService parentService, IClassService classService, ISTSService stsService) { this.studentService = studentService; this.parentService = parentService; this.classService = classService; this.stsService = stsService; }
public void MultipleNestedDoubleParameter() { ServiceContainer services = new ServiceContainer(); services.AddScoped <INestParentService, NestParentService>(); services.AddScoped <ISingleService, SingleService>(); services.AddScoped <IParentService, ParentService>(); services.AddScoped <IFirstChildService, FirstChildService>(); services.AddScoped <ISecondChildService, SecondChildService>(); IContainerScope scope = services.CreateScope(); INestParentService nest = services.Get <INestParentService>(scope); nest.Foo = "nest"; nest.Parent.Foo = "parent"; nest.Parent.First.Foo = "first"; nest.Parent.Second.Foo = "second"; nest.Single.Foo = "single"; INestParentService n1 = services.Get <INestParentService>(scope); Assert.Equal(nest.Foo, n1.Foo); Assert.Equal(nest.Single.Foo, n1.Single.Foo); Assert.Equal(nest.Parent.Foo, n1.Parent.Foo); Assert.Equal(nest.Parent.First.Foo, n1.Parent.First.Foo); Assert.Equal(nest.Parent.Second.Foo, n1.Parent.Second.Foo); IParentService parent = services.Get <IParentService>(scope); Assert.Equal(nest.Parent.Foo, parent.Foo); Assert.Equal(nest.Parent.First.Foo, parent.First.Foo); Assert.Equal(nest.Parent.Second.Foo, parent.Second.Foo); ISingleService single = services.Get <ISingleService>(scope); Assert.Equal(nest.Single.Foo, single.Foo); IFirstChildService first = services.Get <IFirstChildService>(scope); Assert.Equal(nest.Parent.First.Foo, first.Foo); ISecondChildService second = services.Get <ISecondChildService>(scope); Assert.Equal(nest.Parent.Second.Foo, second.Foo); //scopeless should throw error Assert.Throws <ScopeException>(() => services.Get <INestParentService>()); //another scope should not equal IContainerScope scope2 = services.CreateScope(); INestParentService n3 = services.Get <INestParentService>(scope2); Assert.NotEqual(nest.Foo, n3.Foo); Assert.NotEqual(nest.Single.Foo, n3.Single.Foo); Assert.NotEqual(nest.Parent.Foo, n3.Parent.Foo); Assert.NotEqual(nest.Parent.First.Foo, n3.Parent.First.Foo); Assert.NotEqual(nest.Parent.Second.Foo, n3.Parent.Second.Foo); }
public GradeController(UserManager <User> userManager, IGradeService gradeService, IParentService parentService, IStringLocalizer <GradeController> localizer, ILoggerFactory loggerFactory ) : base(localizer, loggerFactory) { _gradeService = gradeService; _parentService = parentService; _userManager = userManager; }
public ReorderEntityDispatcher( IRepositoryResolver repositoryResolver, IParentService parentService, IAuthService authService) { _repositoryResolver = repositoryResolver; _parentService = parentService; _authService = authService; }
public StudentsController(IStudentService studentService, IParentService parentService, IGradeService gradeService, ISubjectService subjectService, IMarkService markService, IClassNumberService classNumberService) { this.studentService = studentService; this.parentService = parentService; this.gradeService = gradeService; this.subjectService = subjectService; this.markService = markService; this.classNumberService = classNumberService; }
public ChildMarksPresenter(IChildMarksView view, IParentService parentService) : base(view) { Validator.ValidateForNull(parentService, "parentService"); this.parentService = parentService; this.View.PageLoad += View_PageLoad; }
public DashboardController(ISchoolService schoolService, IUserService userService, IParentService parentService, IClassBookService classBookService, IScheduleService scheduleService) { this.userService = userService; this.schoolService = schoolService; this.parentService = parentService; this.classBookService = classBookService; this.scheduleService = scheduleService; }
public DeleteEntityDispatcher( IAuthService authService, IRepositoryResolver repositoryResolver, IParentService parentService) { _authService = authService; _repositoryResolver = repositoryResolver; _parentService = parentService; }
public GetEntityDispatcher( ISetupResolver <IEntityVariantSetup> entityVariantResolver, IRepositoryResolver repositoryResolver, IParentService parentService, IAuthService authService) { _entityVariantResolver = entityVariantResolver; _repositoryResolver = repositoryResolver; _parentService = parentService; _authService = authService; }
public PersistEntityDispatcher( IAuthService authService, IRepositoryResolver repositoryResolver, IParentService parentService, IEditContextFactory editContextFactory) { _authService = authService; _repositoryResolver = repositoryResolver; _parentService = parentService; _editContextFactory = editContextFactory; }
public GetEntitiesDispatcher( IRepositoryResolver repositoryResolver, IDataViewResolver dataViewResolver, IParentService parentService, IAuthService authService) { _repositoryResolver = repositoryResolver; _dataViewResolver = dataViewResolver; _parentService = parentService; _authService = authService; }
public ProfileController(RoleManager <IdentityRole> roleManager, IUserService userService, IStudentService studentService, IParentService parentService, ITeacherService teacherService) : base(roleManager) { _userService = userService; _studentService = studentService; _parentService = parentService; _teacherService = teacherService; }
public async Task MultipleNestedDoubleParameter() { ServiceContainer services = new ServiceContainer(); services.AddSingleton <INestParentService, NestParentService>(); services.AddSingleton <ISingleService, SingleService>(); services.AddSingleton <IParentService, ParentService>(); services.AddSingleton <IFirstChildService, FirstChildService>(); services.AddSingleton <ISecondChildService, SecondChildService>(); INestParentService nest = await services.Get <INestParentService>(); nest.Foo = "nest"; nest.Parent.Foo = "parent"; nest.Parent.First.Foo = "first"; nest.Parent.Second.Foo = "second"; nest.Single.Foo = "single"; INestParentService n1 = await services.Get <INestParentService>(); Assert.Equal(nest.Foo, n1.Foo); Assert.Equal(nest.Single.Foo, n1.Single.Foo); Assert.Equal(nest.Parent.Foo, n1.Parent.Foo); Assert.Equal(nest.Parent.First.Foo, n1.Parent.First.Foo); Assert.Equal(nest.Parent.Second.Foo, n1.Parent.Second.Foo); IParentService parent = await services.Get <IParentService>(); Assert.Equal(nest.Parent.Foo, parent.Foo); Assert.Equal(nest.Parent.First.Foo, parent.First.Foo); Assert.Equal(nest.Parent.Second.Foo, parent.Second.Foo); ISingleService single = await services.Get <ISingleService>(); Assert.Equal(nest.Single.Foo, single.Foo); IFirstChildService first = await services.Get <IFirstChildService>(); Assert.Equal(nest.Parent.First.Foo, first.Foo); ISecondChildService second = await services.Get <ISecondChildService>(); Assert.Equal(nest.Parent.Second.Foo, second.Foo); IContainerScope scope = services.CreateScope(); INestParentService n2 = await services.Get <INestParentService>(scope); Assert.Equal(nest.Foo, n2.Foo); Assert.Equal(nest.Single.Foo, n2.Single.Foo); Assert.Equal(nest.Parent.Foo, n2.Parent.Foo); Assert.Equal(nest.Parent.First.Foo, n2.Parent.First.Foo); Assert.Equal(nest.Parent.Second.Foo, n2.Parent.Second.Foo); }
public TreeService( ICollectionProvider collectionProvider, IMetadataProvider metadataProvider, IHttpContextAccessor httpContextAccessor, IAuthorizationService authorizationService, IParentService parentService) { _collectionProvider = collectionProvider; _metadataProvider = metadataProvider; _httpContextAccessor = httpContextAccessor; _authorizationService = authorizationService; _parentService = parentService; }
public AdministratorController(ITeacherService teacherService, IUserService userService, ISchoolService schoolService, IStudentService studentService, IParentService parentService, IClassService classService, ISubjectService subjectService, IStatisticsService statisticsService) { this.teacherService = teacherService; this.userService = userService; this.schoolService = schoolService; this.studentService = studentService; this.parentService = parentService; this.classService = classService; this.subjectService = subjectService; this.statisticsService = statisticsService; }
public TreeService( ICollectionResolver collectionResolver, ICms cms, IRepositoryResolver repositoryResolver, IAuthService authService, IParentService parentService) { _collectionResolver = collectionResolver; _cms = cms; _repositoryResolver = repositoryResolver; _authService = authService; _parentService = parentService; }
public async Task ScopedInSingleton() { ServiceContainer services = new ServiceContainer(); services.AddSingleton <IParentService, ParentService>(); services.AddScoped <IFirstChildService, FirstChildService>(); services.AddScoped <ISecondChildService, SecondChildService>(); await Assert.ThrowsAsync <InvalidOperationException>(async() => await services.Get <IParentService>()); await Assert.ThrowsAsync <InvalidOperationException>(async() => await services.Get <IFirstChildService>()); await Assert.ThrowsAsync <InvalidOperationException>(async() => await services.Get <ISecondChildService>()); IContainerScope scope = services.CreateScope(); IParentService parent = await services.Get <IParentService>(scope); parent.Foo = "parent"; parent.First.Foo = "first"; parent.Second.Foo = "second"; IParentService p1 = await services.Get <IParentService>(scope); Assert.Equal(parent.Foo, p1.Foo); Assert.Equal(parent.First.Foo, p1.First.Foo); Assert.Equal(parent.Second.Foo, p1.Second.Foo); //in same scope, individual scoped items should equal IFirstChildService f1 = await services.Get <IFirstChildService>(scope); ISecondChildService s1 = await services.Get <ISecondChildService>(scope); Assert.Equal(parent.First.Foo, f1.Foo); Assert.Equal(parent.Second.Foo, s1.Foo); //scoped services in singleton should equal (because parent is same) IContainerScope scope2 = services.CreateScope(); IParentService p2 = await services.Get <IParentService>(scope2); Assert.Equal(parent.Foo, p2.Foo); Assert.Equal(parent.First.Foo, p2.First.Foo); Assert.Equal(parent.Second.Foo, p2.Second.Foo); //but individual created scoped items in different scope should not equal IFirstChildService f2 = await services.Get <IFirstChildService>(scope2); ISecondChildService s2 = await services.Get <ISecondChildService>(scope2); Assert.NotEqual(parent.First.Foo, f2.Foo); Assert.NotEqual(parent.Second.Foo, s2.Foo); }
public ChildLecturesPresenter(IChildLecturesView view, IParentService parentService, IStudentService studentService, IDateParser dateParser) : base(view) { Validator.ValidateForNull(parentService, "parentService"); Validator.ValidateForNull(studentService, "studentService"); Validator.ValidateForNull(dateParser, "dateParser"); this.parentService = parentService; this.studentService = studentService; this.dateParser = dateParser; this.View.PageLoad += View_PageLoad; this.View.LoadLectures += View_LoadLectures; }
public async void Nested() { ServiceContainer services = new ServiceContainer(); services.AddScoped <IParentService, ParentService>(); services.AddScoped <IFirstChildService, FirstChildService>(); services.AddScoped <ISecondChildService, SecondChildService>(); IContainerScope scope = services.CreateScope(); IParentService parent = await services.Get <IParentService>(scope); parent.Foo = "parent"; parent.First.Foo = "first"; parent.Second.Foo = "second"; IParentService p1 = await services.Get <IParentService>(scope); Assert.Equal(parent.Foo, p1.Foo); Assert.Equal(parent.First, p1.First); Assert.Equal(parent.Second, p1.Second); Assert.Equal(parent.First.Foo, p1.First.Foo); Assert.Equal(parent.Second.Foo, p1.Second.Foo); IFirstChildService first = await services.Get <IFirstChildService>(scope); ISecondChildService second = await services.Get <ISecondChildService>(scope); Assert.Equal(parent.First, first); Assert.Equal(parent.First.Foo, first.Foo); Assert.Equal(parent.Second.Foo, second.Foo); //scopeless should throw error await Assert.ThrowsAsync <InvalidOperationException>(async() => await services.Get <IParentService>()); await Assert.ThrowsAsync <InvalidOperationException>(async() => await services.Get <IFirstChildService>()); await Assert.ThrowsAsync <InvalidOperationException>(async() => await services.Get <ISecondChildService>()); //another scope should not equal IContainerScope scope2 = services.CreateScope(); IParentService p3 = await services.Get <IParentService>(scope2); Assert.NotEqual(parent.Foo, p3.Foo); Assert.NotEqual(parent.First, p3.First); Assert.NotEqual(parent.Second, p3.Second); Assert.NotEqual(parent.First.Foo, p3.First.Foo); Assert.NotEqual(parent.Second.Foo, p3.Second.Foo); }
public GetEntityDispatcher( ISetupResolver <ICollectionSetup> collectionResolver, IRepositoryResolver repositoryResolver, IParentService parentService, IConcurrencyService concurrencyService, IAuthService authService, IServiceProvider serviceProvider) { _collectionResolver = collectionResolver; _repositoryResolver = repositoryResolver; _parentService = parentService; _concurrencyService = concurrencyService; _authService = authService; _serviceProvider = serviceProvider; }
public void Setup() { _repository = new Mock <IRepository>(); _repository .Setup(x => x.GetByIdAsync(It.IsAny <string>(), It.IsAny <IParent>())) .ReturnsAsync((string id, IParent parent) => { var mock = new Mock <IEntity>(); mock.Setup(x => x.Id).Returns(id); return(mock.Object); }); _repositoryResolver = new Mock <IRepositoryResolver>(); _subject = new ParentService(_repositoryResolver.Object); }
public ParentsController(ILogger logger, IParentService parentService, IAccountService accountService) : base(logger) { this.parentService = parentService; this.accountService = accountService; }
public ChildService2(IParentService xxx) { this.xxx = xxx; }