public void Start() { var uc = new UnityContainer(); var log = new LogAnalizer(); parameterAnalizer = new ParameterAnalizer(); bus = new Bus(); bus.OnMessageReceived += (se, ea) => { var records = ea.Message.body.records.ToArray(); try { log.Analize(records); } catch (Exception ex) { logger.Error("не обработались логером"); } try { parameterAnalizer.Analize(records); } catch (Exception ex) { logger.Error("не обработались параметры"); } }; bus.OnSubscribeMessageReceived += (se, ea) => { Guid sessionId = Guid.Parse(ea.Message.body.sessionId); var ids = new List <Guid>(); foreach (var id in ea.Message.body.ids) { ids.Add(Guid.Parse(id)); } log.Subscribe(sessionId, ids); }; bus.Start(); uc.RegisterInstance(bus); uc.BuildUp(log); uc.RegisterInstance(log); uc.BuildUp(parameterAnalizer); uc.RegisterInstance(parameterAnalizer); var url = ConfigurationManager.AppSettings["service-url"]; webHost = WebApp.Start(url, app => { app.UseNancy(opt => opt.Bootstrapper = new Bootstrapper(uc)); }); logger.Info("сервис запущен, url: {0}", url); }
public void BuildNullObject9() { UnityContainer uc = new UnityContainer(); SimpleClass myObject1 = new SimpleClass(); SimpleClass myObject2 = new SimpleClass(); uc.BuildUp(myObject1, "a"); uc.BuildUp(myObject2, " a "); Assert.AreNotEqual(uc.Resolve(typeof(SimpleClass), "a"), myObject2); }
public void BuildNullObject8() { UnityContainer uc = new UnityContainer(); SimpleClass myObject1 = new SimpleClass(); SimpleClass myObject2 = new SimpleClass(); uc.BuildUp(myObject1, String.Empty); uc.BuildUp(myObject2, " "); Assert.AreNotEqual(uc.Resolve <SimpleClass>(), myObject2); }
public void BuildBaseAndChildObject3() { UnityContainer uc = new UnityContainer(); BaseStub1 objBase = new BaseStub1(); Assert.IsNotNull(objBase); Assert.IsNull(objBase.BaseProp); uc.BuildUp(typeof(BaseStub1), objBase); Assert.IsNotNull(objBase.BaseProp); AssertHelper.ThrowsException <ArgumentException>(() => uc.BuildUp(typeof(ChildStub1), objBase), "type of the object should match"); }
public void BuildNullObject4() { UnityContainer uc = new UnityContainer(); object myNullObject = null; AssertHelper.ThrowsException <ArgumentNullException>(() => uc.BuildUp(typeof(object), myNullObject, "myNullObject"), "Null object is not allowed"); }
protected override WorkflowServiceHost CreateWorkflowServiceHost(WorkflowService service, Uri[] baseAddresses) { var container = new UnityContainer(); ConfigureContainer(container); var host = base.CreateWorkflowServiceHost(service, baseAddresses); var injectionType = ConfigureInjectionType(); if (injectionType == InjectionTypes.Push) { container.AddNewExtension <WorkflowExtension>(); var rootActivity = host.Activity; container.BuildUp(rootActivity.GetType(), rootActivity); } else { var diExtension = new DependencyInjectionExtension(container); host.WorkflowExtensions.Add(diExtension); } ConfigureServiceHost(host); return(host); }
private void RegisterInUnityContainer() { _unityContainer.RegisterInstance(typeof(Map), new Map(curRect)); _unityContainer.RegisterInstance(typeof(StateQueueManager), new StateQueueManager()); _unityContainer.RegisterInstance(typeof(PlannedQueueManager), new PlannedQueueManager()); _unityContainer.RegisterType(typeof(IActionRepository), typeof(ActionRepository), new ContainerControlledLifetimeManager()); _unityContainer.RegisterType(typeof(HeroLifeCycle), typeof(HeroLifeCycle), new ContainerControlledLifetimeManager()); _unityContainer.RegisterType(typeof(DayNightCycle), typeof(DayNightCycle), new ContainerControlledLifetimeManager()); var hero = new Hero(); _unityContainer.BuildUp(hero); _unityContainer.RegisterInstance(typeof(Hero), hero); foreach (var type in Assembly.GetExecutingAssembly().GetTypes().Where(type => !type.IsAbstract && !type.IsInterface && typeof(IAction).IsAssignableFrom(type))) { _unityContainer.RegisterType(typeof(IAction), type, type.ToString(), new ContainerControlledTransientManager(), null); } //_unityContainer.RegisterTypes( //Assembly.GetExecutingAssembly().GetTypes().Where( //), //WithMappings.FromAllInterfacesInSameAssembly,//t => new[] { typeof(IAction) }, //t => t.FullName, //WithLifetime.PerResolve); }
public void BuildNullObject6() { IUnityContainer uc = new UnityContainer(); SimpleClass myObject = new SimpleClass(); uc.BuildUp(myObject, String.Empty); Assert.AreNotEqual(uc.Resolve <SimpleClass>(), myObject); }
public void BuildUpPrimitiveAndDotNetClassTest() { IUnityContainer uc = new UnityContainer(); int i = 0; uc.BuildUp(i, "a"); AssertHelper.ThrowsException <ResolutionFailedException>(() => uc.Resolve(typeof(int), "a")); }
public void BuildUpPrimitiveAndDotNetClassTest() { IUnityContainer uc = new UnityContainer(); int i = 0; uc.BuildUp(i, "a"); var res = uc.Resolve(typeof(int), "a"); }
public void BuildInterfacePropertyInjectTest2() { UnityContainer uc = new UnityContainer(); BarClass2 objBase = new BarClass2(); uc.BuildUp(typeof(IFooInterface2), objBase); Assert.IsNull(objBase.InterfaceProp); }
public void BuildNullObject5() { UnityContainer uc = new UnityContainer(); SimpleClass myObject = new SimpleClass(); uc.BuildUp(myObject, (string)null); Assert.AreNotEqual(uc.Resolve <SimpleClass>(), myObject); }
/// <summary> /// Configures the unity container. /// </summary> private void ConfigureContainer() { var container = new UnityContainer(); // Dude, I just realized that this is not automatic (Why?) ServiceLocator.SetLocatorProvider(() => new UnityServiceLocator(container)); UIConfiguration.Configure(container); CoreConfiguration.Configure(container); container.BuildUp(this); }
public void Cure_For_UnityNotBeingVerySmartAtBindingCircularDependentProperties() { var container = new UnityContainer(); container.RegisterType <ISharedResource, SharedResource>(new ContainerControlledLifetimeManager()); container.RegisterType <ICycleA, CycleA>(new ContainerControlledLifetimeManager(), new InjectionProperty("SharedResource")); container.RegisterType <ICycleB, CycleB>(new ContainerControlledLifetimeManager(), new InjectionProperty("SharedResource")); var a = container.Resolve <ICycleA>(); var b = container.Resolve <ICycleB>(); container.RegisterType <ICycleA, CycleA>("buildup", new ContainerControlledLifetimeManager()); container.RegisterType <ICycleB, CycleB>("buildup", new ContainerControlledLifetimeManager()); container.BuildUp(a, "buildup"); container.BuildUp(b, "buildup"); Assert.IsInstanceOfType(a, typeof(CycleA)); Assert.IsInstanceOfType(a.Dependency, typeof(CycleB)); Assert.AreSame(a, a.Dependency.Dependency); }
private static void Inject(IEnumerable <EntitySystem> systems) { container.RegisterType <IRandom, Utils.Random>(); container.RegisterType <IRules, ExtendedRules>(); container.RegisterInstance <IConsole>(new ConsoleWrapper()); foreach (var system in systems) { container.BuildUp(system.GetType(), system); } }
public void BuildUnmatchedObject1() { UnityContainer uc = new UnityContainer(); BuildUnmatchedObject1_TestClass obj1 = new BuildUnmatchedObject1_TestClass(); uc.BuildUp(typeof(object), obj1); Assert.IsNull(obj1.MyFirstObj); }
public void BuildBaseAndChildObject4() { UnityContainer uc = new UnityContainer(); BaseStub1 objBase = new BaseStub1(); Assert.IsNotNull(objBase); Assert.IsNull(objBase.InterfaceProp); uc.BuildUp(typeof(Interface1), objBase); Assert.IsNotNull(objBase.InterfaceProp); }
//http://unity.codeplex.com/WorkItem/View.aspx?WorkItemId=2618 public void BUG2883_CanResolveTypesWithRefParametersInCtor() { var unity = new UnityContainer(); int count = 0; var test = new TestClassWithRefParametersInCtor(ref count); unity.BuildUp(test); Assert.AreEqual(count, 5); }
public void CanBuildupObjectWithExplicitInterfaceUsingNongenericMethod() { IUnityContainer container = new UnityContainer() .RegisterType <ILogger, MockLogger>(); ObjectWithExplicitInterface o = new ObjectWithExplicitInterface(); container.BuildUp(typeof(ISomeCommonProperties), o); o.ValidateInterface(); }
/// <summary> /// The main entry point for the application. /// </summary> static void Main() { ServiceBase[] ServicesToRun; UnityContainer container = Bootstrapper.Initialize(); ServicesToRun = new ServiceBase[] { container.BuildUp(new AuditAutomationSvc()) }; ServiceBase.Run(ServicesToRun); }
public void CanBuildupObjectWithExplicitInterface() { IUnityContainer container = new UnityContainer() .RegisterType <ILogger, MockLogger>(); ObjectWithExplicitInterface o = new ObjectWithExplicitInterface(); container.BuildUp <ISomeCommonProperties>(o); o.ValidateInterface(); }
public void CanBuildUpExistingObjectOnTypeWithCtorWithOutParameter() { IUnityContainer container = new UnityContainer() .RegisterType<TypeWithConstructorWithOutParameter>(new InjectionProperty("Property", 10)); string ignored = "ignored"; TypeWithConstructorWithOutParameter instance = new TypeWithConstructorWithOutParameter(out ignored); container.BuildUp(instance); Assert.AreEqual(10, instance.Property); }
public void BuildNullObject1() { try { UnityContainer uc = new UnityContainer(); uc.BuildUp((object)null); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(ArgumentNullException)); } }
public SimpleAjaxResult Ready() { try { var serialNo = SerialNoHelper.Create(); var account = AccountService.GetByName(AccountName); if (account == null || !string.Equals(account.AccountToken, AccountToken, StringComparison.OrdinalIgnoreCase)) { throw new Exception(string.Format("会员 '{0}' 未找到", AccountName)); } using (var tran = TransactionHelper.BeginTransaction()) { account.LimiteAmount = LimitAmount; LimitAmountCommand cmd = new LimitAmountCommand(account.AccountId, LimitAmount); UnityContainer.BuildUp(cmd); Helper h = new Helper(cmd.Validate()); if (h.Code != 0) { this.AddError(LogTypes.AccountLimit, "error", ModelHelper.GetBoundText(h, x => x.Code)); return(new SimpleAjaxResult(ModelHelper.GetBoundText(h, x => x.Code))); } if (HostSite.IsLimiteAmountApprove) { //var tasks= TaskService.Query(new TaskRequest() // { // CommandTypeName = Task.GetCommandType(typeof (LimitAmountCommand)), // State = TaskStates.Normal, // AccountId = account.AccountId, // }).ToList(); //foreach (var task in tasks) //{ // TaskService.Delete(task); //} TaskService.Create(new Task(cmd, SecurityHelper.GetCurrentUser().CurrentUser.UserId) { Amount = LimitAmount, AccountId = account.AccountId }); } else { cmd.Execute(SecurityHelper.GetCurrentUser().CurrentUser); } Logger.LogWithSerialNo(LogTypes.AccountLimit, serialNo, account.AccountId, account.Name, LimitAmount); tran.Commit(); return(new SimpleAjaxResult()); } } catch (Exception ex) { Logger.Error(LogTypes.AccountLimit, ex); return(new SimpleAjaxResult(string.Format("内部错误: '{0}'", ex.Message))); } }
public void CanBuildUpExistingObjectOnTypeWithCtorWithOutParameter() { IUnityContainer container = new UnityContainer() .RegisterType <TypeWithConstructorWithOutParameter>(new InjectionProperty("Property", 10)); string ignored = "ignored"; TypeWithConstructorWithOutParameter instance = new TypeWithConstructorWithOutParameter(out ignored); container.BuildUp(instance); Assert.AreEqual(10, instance.Property); }
public void ShouldNotThrowIfValidationOnParameterAttributePasses() { IUnityContainer factory = new UnityContainer().AddNewExtension <Interception>(); factory.Configure <Interception>().SetDefaultInterceptorFor <TestObject>(new TransparentProxyInterceptor()); AddValidationPolicy(factory, string.Empty, SpecificationSource.Both, new TypeMatchingRule("TestObject")); TestObject target = factory.BuildUp <TestObject>(new TestObject(false, false)); target.GetValueByKey("key"); }
public void BuildUnmatchedObject2() { UnityContainer uc = new UnityContainer(); BuildUnmatchedObject2__PropertyDependencyClassStub2 obj2 = new BuildUnmatchedObject2__PropertyDependencyClassStub2(); Assert.IsNotNull(obj2); Assert.IsNull(obj2.MyFirstObj); Assert.IsNull(obj2.MySecondObj); AssertHelper.ThrowsException <ArgumentException>(() => uc.BuildUp(typeof(BuildUnmatchedObject2_PropertyDependencyClassStub1), obj2), "type of the object should match"); }
public void Test() { UnityContainer container = new UnityContainer(); container.RegisterInstance <IAnimal>(nameof(Dog), new Dog()); container.RegisterInstance <IAnimal>(nameof(Cat), new Cat()); var person = new Person(); person = container.BuildUp(person); person.Call(); }
public void CanBuildUpExistingObjectWithNonGenericObject() { IUnityContainer container = new UnityContainer() .RegisterType <ILogger, MockLogger>(); ObjectUsingLogger o = new ObjectUsingLogger(); object result = container.BuildUp(o); AssertExtensions.IsInstanceOfType(result, typeof(ObjectUsingLogger)); Assert.AreSame(o, result); Assert.IsNotNull(o.Logger); AssertExtensions.IsInstanceOfType(o.Logger, typeof(MockLogger)); }
public void CanDoInjectionOnExistingObjects() { IUnityContainer container = new UnityContainer(); ObjectWithTwoProperties o = new ObjectWithTwoProperties(); Assert.IsNull(o.Obj1); Assert.IsNull(o.Obj2); container.BuildUp(o); o.Validate(); }
protected void Page_Load(object sender, EventArgs e) { //productoBL = new ProductoBL(); using (var container = new UnityContainer()) { container.LoadConfiguration(); container.BuildUp(this.GetType(), this); } gvProductos.DataSource = productoBL.GetAllFromProducto(); gvProductos.DataBind(); }