public void CanReturnServiceIfInitializedAndRegistered() { IWindsorContainer container = new WindsorContainer(); container.AddComponent("validator", typeof(IValidator), typeof(Validator)); ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(container)); IValidator validatorService = SafeServiceLocator <IValidator> .GetService(); Assert.That(validatorService, Is.Not.Null); }
public override bool IsValid(object value) { var entityToValidate = value as IEntityWithTypedId <int>; Check.Require( entityToValidate != null, "This validator must be used at the class level of an IDomainWithTypedId<int>. The type you provided was " + value.GetType()); var duplicateChecker = SafeServiceLocator <IEntityDuplicateChecker> .GetService(); return(!duplicateChecker.DoesDuplicateExistWithTypedIdOf(entityToValidate)); }
public override void OnActionExecuted(ActionExecutedContext filterContext) { IDocumentSession session = SafeServiceLocator <IDocumentSession> .GetService(); if (((filterContext.Exception != null) && filterContext.ExceptionHandled) || this.ShouldRollback(filterContext)) { return; } session.SaveChanges(); }
public bool IsValid(object value, IConstraintValidatorContext constraintValidatorContext) { IEntityWithTypedId <int> entityToValidate = value as IEntityWithTypedId <int>; Check.Require(entityToValidate != null, "This validator must be used at the class level of an " + "IdomainWithTypedId<int>. The type you provided was " + value.GetType().ToString()); IEntityDuplicateChecker duplicateChecker = SafeServiceLocator <IEntityDuplicateChecker> .GetService(); return(!duplicateChecker.DoesDuplicateExistWithTypedIdOf <int>(entityToValidate)); }
public void WillBeInformedIfServiceLocatorNotInitialized() { bool exceptionThrown = false; try { SafeServiceLocator <IValidator> .GetService(); } catch (NullReferenceException e) { exceptionThrown = true; Assert.That(e.Message.Contains("ServiceLocator has not been initialized")); } Assert.That(exceptionThrown); }
public bool IsValid(object value, IConstraintValidatorContext constraintValidatorContext) { IEntityWithTypedId <string> entityToValidate = value as IEntityWithTypedId <string>; Check.Require(entityToValidate != null, "This validator must be used at the class level of an " + "IdomainWithTypedId<string>. The type you provided was " + value.GetType().ToString() + ". " + "Other validators exist for various Id types. Please open an issue with S#arp Architecture " + "if you need a new Id type supported; you can make your own in the meantime."); IEntityDuplicateChecker duplicateChecker = SafeServiceLocator <IEntityDuplicateChecker> .GetService(); return(!duplicateChecker.DoesDuplicateExistWithTypedIdOf <string>(entityToValidate)); }
public void WillBeInformedIfServiceNotRegistered() { bool exceptionThrown = false; IWindsorContainer container = new WindsorContainer(); ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(container)); try { SafeServiceLocator <IValidator> .GetService(); } catch (ActivationException e) { exceptionThrown = true; Assert.That(e.Message.Contains("IValidator could not be located")); } Assert.That(exceptionThrown); }
public OutfitEngineService() { // HACK: To support multiple calls from WCF Service, we need to create the dependencies here. garmentRepository = SafeServiceLocator <IGarmentRepository> .GetService(); closetRepository = SafeServiceLocator <IClosetRepository> .GetService(); fashionFlavorRepository = SafeServiceLocator <IFashionFlavorRepository> .GetService(); // HACK: We create always a new Processor to avoid conflicts if retrieve it directly from Locator as it works like Singleton. processor = new OutfitEngineProcessor( SafeServiceLocator <IStyleRuleRepository> .GetService(), SafeServiceLocator <IClosetRepository> .GetService(), SafeServiceLocator <IOutfitUpdaterService> .GetService(), SafeServiceLocator <IIndexCreationService> .GetService()); logger = log4net.LogManager.GetLogger(this.GetType().Namespace); logger.Info("Constructor called"); }
public static string GetKey() { var provider = SafeServiceLocator <ISessionFactoryKeyProvider> .GetService(); return(provider.GetKey()); }
public static string GetKeyFrom(object anObject) { var provider = SafeServiceLocator <ISessionFactoryKeyProvider> .GetService(); return(provider.GetKeyFrom(anObject)); }
public CotRoleProvider() { _personManagementService = SafeServiceLocator <IPersonManagementService> .GetService(); }