本文整理汇总了C#中Microsoft.Practices.Unity.UnityContainer.BuildUp方法的典型用法代码示例。如果您正苦于以下问题:C# UnityContainer.BuildUp方法的具体用法?C# UnityContainer.BuildUp怎么用?C# UnityContainer.BuildUp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Practices.Unity.UnityContainer
的用法示例。
在下文中一共展示了UnityContainer.BuildUp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildNullObject7
public void BuildNullObject7()
{
UnityContainer uc = new UnityContainer();
SimpleClass myObject1 = new SimpleClass();
SimpleClass myObject2 = new SimpleClass();
uc.BuildUp(myObject1, String.Empty);
uc.BuildUp(myObject2, (string)null);
Assert.AreNotEqual(uc.Resolve<SimpleClass>(), myObject2);
}
示例2: CreateWorkflowServiceHost
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;
}
示例3: BuildNullObject4
public void BuildNullObject4()
{
UnityContainer uc = new UnityContainer();
object myNullObject = null;
AssertHelper.ThrowsException<ArgumentNullException>(() => uc.BuildUp(typeof(object), myNullObject, "myNullObject"), "Null object is not allowed");
}
示例4: BuildNullObject6
public void BuildNullObject6()
{
UnityContainer uc = new UnityContainer();
SimpleClass myObject = new SimpleClass();
uc.BuildUp(myObject, String.Empty);
Assert.AreNotEqual(uc.Resolve<SimpleClass>(), myObject);
}
示例5: CreateServiceHost
/// <summary>
/// When overridden in a derived class, creates a <see cref="T:System.ServiceModel.ServiceHostBase"/> with a specific base address using custom initiation data.
/// </summary>
/// <param name="constructorString">The initialization data that is passed to the <see cref="T:System.ServiceModel.ServiceHostBase"/> instance being constructed by the factory.</param>
/// <param name="baseAddresses">An <see cref="T:System.Array"/> of type <see cref="T:System.Uri"/> that contains the base addresses of the host.</param>
/// <returns>
/// The <see cref="T:System.ServiceModel.ServiceHostBase"/> object with the specified base addresses and initialized with the custom initiation data.
/// </returns>
public override ServiceHostBase CreateServiceHost(
string constructorString,
Uri[] baseAddresses)
{
var container = new UnityContainer().LoadConfiguration();
var instance = new ClientService { Container = container };
container.BuildUp(instance);
var serviceBusHost = new ServiceHost(instance, baseAddresses);
return serviceBusHost;
}
示例6: TypeBasedOverrideWithBuildUp
public void TypeBasedOverrideWithBuildUp()
{
MySimpleType instance = new MySimpleType();
instance.X = 111;
PropertyOverride overrideParam = new PropertyOverride("X", 222);
TypeBasedOverride overrideDecorator = new TypeBasedOverride(typeof(MySimpleType), overrideParam);
UnityContainer container = new UnityContainer();
var result = container.BuildUp<MySimpleType>(instance, overrideDecorator);
Assert.AreEqual<int>(222, result.X);
}
示例7: Check2PropertyDependencyBuildUpWorks
public void Check2PropertyDependencyBuildUpWorks()
{
UnityContainer uc = new UnityContainer();
My2PropertyDependencyClass obj1 = new My2PropertyDependencyClass();
Assert.IsNotNull(obj1);
Assert.IsNull(obj1.MyFirstObj);
Assert.IsNull(obj1.MySecondObj);
uc.BuildUp(obj1);
Assert.IsNotNull(obj1.MyFirstObj);
Assert.IsNotNull(obj1.MySecondObj);
}
示例8: BuildupLazyInstance
public void BuildupLazyInstance()
{
IUnityContainer container = new UnityContainer();
container.RegisterType<Lazy<EmailService>>();
var lazyDependency = new Lazy<LazyDependency>();
var lazy = container.BuildUp(lazyDependency);
var lazyreturned = container.Resolve<Lazy<LazyDependency>>();
Assert.AreEqual(lazy, lazyDependency);
Assert.IsFalse(lazyreturned.IsValueCreated);
var ld = (LazyDependency)lazyreturned.Value;
Assert.IsFalse(ld.Service.IsValueCreated);
Assert.IsNotNull(ld.Service.Value);
}
示例9: Main
private static void Main(string[] args)
{
if (args.Length == 0)
{
args = new[] { "10", "+", "20", "+", "30" };
}
using (var container = new UnityContainer())
{
Bootstrapper.SetupContainer(container);
var calculator = container.Resolve<ICalculator>();
int result = calculator.Evaluate(args);
var resultWriter = container.BuildUp(new ConsoleAndFileResultWriter("output.txt"));
resultWriter.WriteResult(result);
}
}
示例10: BuildBaseAndChildObject4
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);
}
示例11: IntegrationWithBitcoinDaemonTest
public void IntegrationWithBitcoinDaemonTest()
{
var accountId = UnitTestHelper.Random.Next(1, int.MaxValue);
var container = new UnityContainer();
var logger = LogManager.GetLogger(typeof(IncomingTransactionProcessorTests));
container.RegisterInstance(logger);
var mockService = new Mock<IClientService>(MockBehavior.Strict);
container.RegisterInstance(mockService.Object);
var mockRpcClient = new Mock<RpcClient> { CallBase = true };
mockRpcClient.Object.Hostname = "127.0.0.1";
mockRpcClient.Object.PortNumber = 8502;
mockRpcClient.Object.Credential = new NetworkCredential("user", "password");
container.RegisterInstance<IRpcClient>(mockRpcClient.Object);
var processor = new Mock<IncomingTransactionProcessor> { CallBase = true };
container.BuildUp(processor.Object);
var amount = 0.00001m * UnitTestHelper.Random.Next(1, 100);
// Locate the most recent transaction before this point
// TODO: Magic number
var lastTransaction =
mockRpcClient.Object.GetTransactions(null, 100, 0).OrderBy(x => x.Time).Where(x => x.Category == "receive").LastOrDefault();
var lastTransactionId = lastTransaction == null ? null : lastTransaction.TransactionId;
Console.WriteLine("Last transaction (actual) before test is " + lastTransactionId ?? "<none>");
// Create a new address for the account
var accountAddress = mockRpcClient.Object.GetNewAddress(accountId.ToString(CultureInfo.InvariantCulture));
Console.WriteLine("New address for account " + accountId + " is " + accountAddress);
// Send the amount
var transactionId = mockRpcClient.Object.Send("Free", accountAddress, amount);
Console.WriteLine("Sent " + amount + " BTC from 'Free' to " + accountAddress + " with transaction id #" + transactionId);
var sessionId = Guid.NewGuid();
mockService.Setup(s => s.GetLastProcessedTransactionId(sessionId)).Returns(lastTransactionId);
mockService.Setup(s => s.TransactionIsProcessed(sessionId, transactionId)).Returns(false);
mockService.Setup(s => s.CreditTransactionWithHold(sessionId, accountId, transactionId, amount, "EXU"));
mockService.Setup(s => s.ReleaseTransactionHold(sessionId, transactionId));
Console.WriteLine("Processing transaction log. Mocking will prevent anything but #" + transactionId + " from being processed.");
// Act
processor.Object.Process(sessionId);
// Assert
mockService.Verify(s => s.GetLastProcessedTransactionId(sessionId));
mockService.Verify(s => s.TransactionIsProcessed(sessionId, transactionId));
mockService.Verify(s => s.CreditTransactionWithHold(sessionId, accountId, transactionId, amount, "EXU"));
mockService.Verify(s => s.ReleaseTransactionHold(sessionId, transactionId));
}
示例12: SuccessfulProcessTransaction1
public void SuccessfulProcessTransaction1()
{
var accountId = UnitTestHelper.Random.Next(1, int.MaxValue);
var transaction = new Transaction
{
Account = accountId.ToString(CultureInfo.InvariantCulture),
Address = UnitTestHelper.Random.Next(1, int.MaxValue).ToString(CultureInfo.InvariantCulture),
Amount = (decimal)(UnitTestHelper.Random.NextDouble() * 10000) / 100m,
Category = "receive",
Confirmations = UnitTestHelper.Random.Next(1, 250),
Time = DateTime.UtcNow.AddDays(-UnitTestHelper.Random.Next(1, 100)),
TransactionId = UnitTestHelper.Random.Next(1, int.MaxValue).ToString(CultureInfo.InvariantCulture)
};
var container = new UnityContainer();
var logger = LogManager.GetLogger(typeof(IncomingTransactionProcessorTests));
container.RegisterInstance(logger);
var sessionId = Guid.NewGuid();
var mockService = new Mock<IClientService>(MockBehavior.Strict);
mockService.Setup(s => s.TransactionIsProcessed(sessionId, transaction.TransactionId)).Returns(false);
mockService.Setup(s => s.CreditTransactionWithHold(sessionId, accountId, transaction.TransactionId, transaction.Amount, "EXU"));
mockService.Setup(s => s.ReleaseTransactionHold(sessionId, transaction.TransactionId));
container.RegisterInstance(mockService.Object);
var mockRpcClient = new Mock<IRpcClient>(MockBehavior.Strict);
mockRpcClient.Setup(r => r.Move(transaction.Account, "EXU", transaction.Amount, 1, null));
container.RegisterInstance(mockRpcClient.Object);
var processor = new Mock<IncomingTransactionProcessor>() { CallBase = true };
container.BuildUp(processor.Object);
// Act
processor.Object.Process(sessionId, transaction);
// Assert
mockService.Verify(s => s.TransactionIsProcessed(sessionId, transaction.TransactionId), Times.Once());
mockService.Verify(s => s.CreditTransactionWithHold(sessionId, accountId, transaction.TransactionId, transaction.Amount, "EXU"), Times.Once());
mockService.Verify(s => s.ReleaseTransactionHold(sessionId, transaction.TransactionId), Times.Once());
mockRpcClient.Verify(r => r.Move(transaction.Account, "EXU", transaction.Amount, 1, null), Times.Once());
}
示例13: ShouldNotThrowIfValidationOnParameterAttributePasses
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");
}
示例14: BuildUpPrimitiveAndDotNetClassTest
public void BuildUpPrimitiveAndDotNetClassTest()
{
IUnityContainer uc = new UnityContainer();
int i = 0;
uc.BuildUp(i, "a");
AssertHelper.ThrowsException<ResolutionFailedException>(() => uc.Resolve(typeof(int), "a"));
}
示例15: BuildUnmatchedObject1
public void BuildUnmatchedObject1()
{
UnityContainer uc = new UnityContainer();
BuildUnmatchedObject1_TestClass obj1 = new BuildUnmatchedObject1_TestClass();
uc.BuildUp(typeof(object), obj1);
Assert.IsNull(obj1.MyFirstObj);
}