本文整理汇总了C#中Microsoft.Practices.Unity.UnityContainer.AddNewExtension方法的典型用法代码示例。如果您正苦于以下问题:C# UnityContainer.AddNewExtension方法的具体用法?C# UnityContainer.AddNewExtension怎么用?C# UnityContainer.AddNewExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Practices.Unity.UnityContainer
的用法示例。
在下文中一共展示了UnityContainer.AddNewExtension方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Application_Start
/// <summary>
/// Starts the application.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">A <see cref="EventArgs"/> that contains the event data.</param>
protected void Application_Start(object sender, EventArgs e)
{
IConfigurationSource config = ConfigurationSourceFactory.Create();
Logger.SetLogWriter(new LogWriterFactory(config).Create());
ExceptionPolicy.SetExceptionManager(new ExceptionPolicyFactory(config).CreateManager());
try
{
IUnityContainer container = new UnityContainer().LoadConfiguration();
container.AddNewExtension<SecurityDependencyContainer>();
container.AddNewExtension<WorflowDependencyContainer>();
DependencyInjectionContainer = container;
JsonConvert.DefaultSettings = () => new JsonSerializerSettings
{
Formatting = Formatting.None,
ContractResolver = new DiscretionalContractResolver(),
Converters = new JsonConverter[] { new JsonKnownTypeConverter() }
};
}
catch (Exception ex)
{
bool rethrow = ExceptionPolicy.HandleException(ex, "Default");
if (rethrow)
{
throw;
}
}
}
示例2: ApiSetup
static ApiSetup()
{
try
{
//Create
Container = new UnityContainer();
Locator = new UnityServiceLocator(Container);
//Add entlib extensions
Container.AddNewExtension<EnterpriseLibraryCoreExtension>();
#pragma warning disable 612,618
Container.AddNewExtension<CachingBlockExtension>();
#pragma warning restore 612,618
ServiceLocator.SetLocatorProvider(() => Locator);
Container.LoadConfiguration("api");
ApiDefaultConfig.DoDefaultRegistrations(Container);
//NOTE: disabled for now
//try
//{
// ApiDefaultConfig.DoAutomaticConfiguration(Container);
// Initialization.Add(ApiSetupState.UnityAutoRegitrations, null);
//}
//catch (Exception e)
//{
// Initialization.Add(ApiSetupState.UnityAutoRegitrations, new[] { e });
//}
}
catch (Exception e)
{
Initialization.Add(ApiSetupState.UnityRegitrations, new[] { e });
throw;
}
Initialization.Add(ApiSetupState.UnityRegitrations, null);
}
示例3: Configure
public static UnityContainer Configure()
{
var container = new UnityContainer();
container.AddNewExtension<DataModule>();
container.AddNewExtension<ProvidersModule>();
container.AddNewExtension<ServiceModule>();
container.AddNewExtension<AnalyticsModule>();
return container;
}
示例4: Compose
public static IDependencyInjectionContainer Compose()
{
var container = new UnityContainer();
container.AddNewExtension<MvcSiteMapProviderContainerExtension>();
container.AddNewExtension<MvcDemosContainerExtension>();
GlobalConfiguration.Configuration.DependencyResolver = new UnityDependencyResolver(container);
return new UnityDependencyInjectionContainer(container);
}
示例5: RegisterComponents
public static void RegisterComponents()
{
var container = new UnityContainer();
container.AddNewExtension<QueriesExtension>();
container.AddNewExtension<AuthenticationExtension>();
container.AddNewExtension<CommandsExtension>();
container.AddNewExtension<CommonServicesExtension>();
container.AddNewExtension<WorkflowsExtension>();
DependencyResolver.SetResolver(new UnityDependencyResolver(container));
}
示例6: Application_Start
protected void Application_Start()
{
XmlConfigurator.Configure();
var container = new UnityContainer();
container.AddNewExtension<Bootstrapper>();
GlobalConfiguration.Configure(WebApiConfig.Register);
}
示例7: Main
public static void Main()
{
XmlConfigurator.Configure();
var settings = new Settings();
var container = new UnityContainer();
container.AddNewExtension<Bootstrapper>();
HostFactory.Run(c =>
{
c.UseUnityContainer(container);
c.UseLog4Net();
c.SetServiceName(settings.ServiceName);
c.SetDisplayName(settings.ServiceDisplayName);
c.SetDescription(settings.ServiceDescription);
c.Service<ServiceStarter>(s =>
{
s.ConstructUsingUnityContainer();
s.WhenStarted(pcs => pcs.Start());
s.WhenStopped(_ => { });
});
});
System.Console.ReadKey();
}
示例8: OnStartup
protected override void OnStartup(StartupEventArgs e)
{
IUnityContainer container = new UnityContainer();
container.AddNewExtension<LazySupportExtension>();
// Register grooveshark related stuff
container.RegisterType<IGroovesharkClient, GroovesharkClientWrapper>(
new ContainerControlledLifetimeManager(),
new InjectionMethod("Connect"));
container.RegisterType<ISongProvider, GroovesharkSongProvider>(
GroovesharkSongProvider.ProviderName,
new ContainerControlledLifetimeManager());
container.RegisterType<ISongPlayer, GroovesharkSongPlayer>(
GroovesharkSongProvider.ProviderName,
new ContainerControlledLifetimeManager());
// Register spotify/torshify related stuff
container.RegisterType<ISongProvider, SpotifySongProvider>(
SpotifySongProvider.ProviderName,
new ContainerControlledLifetimeManager());
container.RegisterType<ISongPlayer, TorshifySongPlayerClient>(
SpotifySongProvider.ProviderName,
new ContainerControlledLifetimeManager());
container.RegisterType<ISpotifyImageProvider, TorshifyImageProvider>();
// Aggregate provider that combines Grooveshark and Spotify players and providers
container.RegisterType<ISongProvider, AggregateSongProvider>(new InjectionFactory(c =>
{
var a = new AggregateSongProvider(
c.Resolve<ISongProvider>(GroovesharkSongProvider.ProviderName),
c.Resolve<ISongProvider>(SpotifySongProvider.ProviderName));
a.UnhandledException += (sender, args) =>
{
Trace.WriteLine(args.Exception);
args.Handled = true;
};
return a;
}));
container.RegisterType<ISongPlayer, AggregateSongPlayer>(new InjectionFactory(c =>
{
return new AggregateSongPlayer(
c.Resolve<ISongPlayer>(GroovesharkSongProvider.ProviderName),
c.Resolve<ISongPlayer>(SpotifySongProvider.ProviderName));
}));
TorshifyServerProcessHandler torshifyServerProcess = new TorshifyServerProcessHandler();
torshifyServerProcess.CloseServerTogetherWithClient = true;
//torshifyServerProcess.Hidden = true;
torshifyServerProcess.TorshifyServerLocation = Path.Combine(Environment.CurrentDirectory, "TRock.Music.Torshify.Server.exe");
torshifyServerProcess.UserName = "<insert username>";
torshifyServerProcess.Password = "<insert password>";
torshifyServerProcess.Start();
var provider = container.Resolve<ISongProvider>();
MainWindow = container.Resolve<MainWindow>();
MainWindow.Show();
}
示例9: Test
public void Test()
{
using (var container = new UnityContainer())
{
container.RegisterType<ITestClass, TestClass>();
container.AddNewExtension<LazyExtension>();
var testClass1 = container.Resolve<Lazy<ITestClass>>();
Assert.AreEqual(false, testClass1.IsValueCreated);
Assert.AreEqual(0, TestClass.InstanceCount);
Assert.AreEqual(5, testClass1.Value.HighFive());
Assert.AreEqual(true, testClass1.IsValueCreated);
Assert.AreEqual(1, TestClass.InstanceCount);
var testClass2 = container.Resolve<Lazy<ITestClass>>();
Assert.AreEqual(false, testClass2.IsValueCreated);
Assert.AreEqual(1, TestClass.InstanceCount);
Assert.AreEqual(5, testClass2.Value.HighFive());
Assert.AreEqual(true, testClass2.IsValueCreated);
Assert.AreEqual(2, TestClass.InstanceCount);
}
}
示例10: Setup
public void Setup()
{
container = new UnityContainer();
container.AddNewExtension<Interception>();
container.RegisterTypeWithCallHandler<ArgumentNotNullHandler, ArgumentNotNullTest>();
sample = container.Resolve<ArgumentNotNullTest>();
}
示例11: MassDisposable_Test
public void MassDisposable_Test()
{
var container = new UnityContainer();
container.AddNewExtension<DisposableStrategyExtension>();
container.RegisterType<DisposableClass>(new DisposingTransientLifetimeManager());
var sw = new Stopwatch();
sw.Start();
var objects = new List<DisposableClass>();
for (int i = 0; i < 10000; i++)
{
objects.Add(container.Resolve<DisposableClass>());
}
sw.Stop();
Context.WriteLine("Resolve: " + sw.Elapsed.ToString());
sw.Restart();
for (int i = 0; i < 10000; i++)
{
container.Teardown(objects[i]);
Assert.IsTrue(objects[i].Disposed);
}
sw.Stop();
Context.WriteLine("Teardown: " + sw.Elapsed.ToString());
}
示例12: Compose
public static IDependencyInjectionContainer Compose()
{
var container = new UnityContainer();
container.AddNewExtension<MvcSiteMapProviderContainerExtension>();
return new UnityDependencyInjectionContainer(container);
}
示例13: Combined_Test
public void Combined_Test()
{
var container = new UnityContainer();
container.AddNewExtension<DisposableStrategyExtension>();
container.RegisterType<DisposableClass>("transient", new DisposingTransientLifetimeManager());
container.RegisterType<DisposableClass>("shared", new DisposingSharedLifetimeManager());
var transient1 = container.Resolve<DisposableClass>("transient");
var transient2 = container.Resolve<DisposableClass>("transient");
Assert.AreNotEqual(transient1, transient2);
var shared1 = container.Resolve<DisposableClass>("shared");
Assert.AreNotEqual(transient1, shared1);
Assert.AreNotEqual(transient2, shared1);
var shared2 = container.Resolve<DisposableClass>("shared");
Assert.AreEqual(shared1, shared2);
container.Teardown(transient1);
Assert.IsTrue(transient1.Disposed);
container.Teardown(shared2);
Assert.IsFalse(shared2.Disposed);
container.Teardown(shared1);
Assert.IsTrue(shared1.Disposed);
}
示例14: UnityCanResolveEnumerableOfTypesRegisteredInUnityTest
public void UnityCanResolveEnumerableOfTypesRegisteredInUnityTest()
{
// Setup
var unityContainer = new UnityContainer();
// Add composition support for unity
unityContainer.AddNewExtension<LazySupportExtension>();
Component1.InstanceCount = 0;
Component2.InstanceCount = 0;
unityContainer.RegisterType<IComponent, Component1>("component1");
unityContainer.RegisterType<IComponent, Component2>("component2");
unityContainer.RegisterType<IComponent, Component3>();
var collectionOfLazyUnityComponents = unityContainer.Resolve<IEnumerable<IComponent>>();
Assert.That(collectionOfLazyUnityComponents, Is.Not.Null);
Assert.That(Component1.InstanceCount, Is.EqualTo(1));
Assert.That(Component2.InstanceCount, Is.EqualTo(1));
var list = new List<IComponent>(collectionOfLazyUnityComponents);
Assert.That(list.Count, Is.EqualTo(3));
Assert.That(list.OfType<Component1>().Count(), Is.EqualTo(1));
Assert.That(list.OfType<Component2>().Count(), Is.EqualTo(1));
Assert.That(list.OfType<Component3>().Count(), Is.EqualTo(1));
}
示例15: RegisterRepositoryTypes
public static void RegisterRepositoryTypes(UnityContainer container)
{
/* Register types into the container */
container.RegisterType<IDataService, DataService>();
//container.RegisterType<IDataService, DummyDataService>();
/* Register the Logger to be used by all calls from the container */
container.RegisterType<LogHelper, LogHelper>(new ContainerControlledLifetimeManager());
/* Register our data access helper to be used uniquely for each thread call from container */
container.RegisterType<IDataAccessor, DataAccessor>(new PerThreadLifetimeManager());
/* Register our matching rule and call handlers (AKA Aspects) */
container.RegisterType<IMatchingRule, AllMatchingRule>(MatchingRule);
container.RegisterType<ICallHandler, ExceptionCallHandler>(ExceptionCallHandler.Key);
container.RegisterType<ICallHandler, UnitOfWorkCallHandler>(UnitOfWorkCallHandler.Key);
container.RegisterType<ICallHandler, AuthenticationCallHandler>(AuthenticationCallHandler.Key);
container.RegisterType<ICallHandler, CommandCallHandler>(CommandCallHandler.Key);
container.RegisterType<ICallHandler, LogCallHandler>(LogCallHandler.Key);
/* Create a new policy and reference the matching rule and call handler by name */
container.AddNewExtension<Interception>();
container.Configure<Interception>()
.AddPolicy(PolicyName)
.AddMatchingRule(MatchingRule)
.AddCallHandler(ExceptionCallHandler.Key)
.AddCallHandler(UnitOfWorkCallHandler.Key)
//.AddCallHandler(LogCallHandler.Key)
.AddCallHandler(AuthenticationCallHandler.Key)
.AddCallHandler(CommandCallHandler.Key);
/* Make IDataService interface elegible for interception */
container.Configure<Interception>().SetInterceptorFor(typeof(IDataService), new TransparentProxyInterceptor());
}