本文整理汇总了C#中IUnityContainer.AddNewExtension方法的典型用法代码示例。如果您正苦于以下问题:C# IUnityContainer.AddNewExtension方法的具体用法?C# IUnityContainer.AddNewExtension怎么用?C# IUnityContainer.AddNewExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IUnityContainer
的用法示例。
在下文中一共展示了IUnityContainer.AddNewExtension方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RegisterDependencies
/// <summary>
/// Additionally configures unity container with classes in Database access project
/// </summary>
/// <param name="container">Unity container instance</param>
public static void RegisterDependencies(IUnityContainer container)
{
container.RegisterType<IServiceBehavior, UmaConnNHibernateBehavior>("nHibernate");
container.RegisterInstance<ISessionFactory>(UmaConnNhibernateFactory.Instance, new ContainerControlledLifetimeManager());
container.RegisterType<ISession>(
new HierarchicalLifetimeManager(),
new InjectionFactory(c => container.Resolve<ISessionFactory>().OpenSession()));
container.RegisterType<IUmaMasterDataService, UmaMasterDataService>();
container.RegisterType<ICallHandler, UmaConnTransactionHandler>("TransactionHandler");
container.AddNewExtension<Interception>();
container.Configure<Interception>().SetInterceptorFor<UmaMasterDataService>(new TransparentProxyInterceptor());
// These extensions will handle cases where
// ILog is resolved as Property with [Dependency] attribute.
// Will create Logger with name of resolving Type.
// http://blog.baltrinic.com/software-development/dotnet/log4net-integration-with-unity-ioc-container
container
.AddNewExtension<BuildTracking>()
.AddNewExtension<LogCreation>();
// DO NOT DELETE THIS CODE UNLESS WE NO LONGER REQUIRE ASSEMBLY NLOG.EXTENDED!!!
var dummyCall = typeof(NLog.Web.NLogHttpModule);
var ok = dummyCall.Assembly.CodeBase;
}
示例2: Register
public void Register(IUnityContainer unityContainer)
{
// this tracks the build-order for each resolve call
unityContainer.AddNewExtension<BuildTrackingExtension>();
// this creates the logger instance, depending on the resolve-callee over the BuildTracking
unityContainer.AddNewExtension<LogCreationExtension>();
// register the ILog type
unityContainer.RegisterType<ILog>(new TransientLifetimeManager());
}
示例3: RegisterTypes
public void RegisterTypes(IUnityContainer container)
{
container.AddNewExtension<Interception>();
container.RegisterType<ITypeAdapter, AutoMapperTypeAdapter>()
.RegisterType<ICacheProvider, EntLibCacheProvider>(new ContainerControlledLifetimeManager())
//异常记录器
.RegisterType<ILogger, Log4netLogger>(LoggerName.ExceptionLogger.ToString(), new InjectionConstructor(LoggerName.ExceptionLogger.ToString()))
//日志记录器
.RegisterType<ILogger, Log4netLogger>(LoggerName.Logger.ToString(), new InjectionConstructor(LoggerName.Logger.ToString()))
.RegisterType<IRepositoryContext, EntityFrameworkRepositoryContext>()
.RegisterType<IRepository<IAggregateRoot>, EntityFrameworkRepository<IAggregateRoot>>();
////测试异常日志AOP专用
//var repo = new MockRepository();
//var stub = repo.Stub<ITermRepository>();
//stub.Expect(t => t.GetAll())
// .Throw(new ArgumentNullException("测试抛出的异常"));
//repo.ReplayAll();
//container.RegisterInstance<ITermRepository>(stub);
//执行异常日志测试时,注释该语句
container.RegisterType<ITermRepository, TermRepository>();
container.RegisterType<ITermAppl, TermAppl>(
//new Interceptor<InterfaceInterceptor>(),
//new InterceptionBehavior<CacheBehavior>(),
//new InterceptionBehavior<ExceptionLoggerBehavior>()
);
}
示例4: Init
public static void Init(TestContext context)
{
GetMockSubscribeService();
GetMockCurrentHttpContext();
CreateBasicSubmission();
CreateComplexSubmission();
CreateBasicEnergySubmission();
CreateComplexEnergySubmission();
CreateBasicCargoSubmission();
CreateComplexCargoSubmission();
CreateBasicHullSubmission();
CreateComplexHullSubmission();
CreateBasicMarineSubmission();
CreateComplexMarineSubmission();
_container = new UnityContainer();
_container.AddNewExtension<EnterpriseLibraryCoreExtension>();
_container.RegisterType<ILogHandler, LogHandler>();
_container.RegisterType<IConsoleRepository, ConsoleRepository>();
_container.RegisterType<IWebSiteModuleManager, WebSiteModuleManager>();
var mockPolicyData = new Mock<IPolicyData>();
//_container.RegisterType<IPolicyData, PolicyData>();
_container.RegisterInstance(typeof(IPolicyData), mockPolicyData.Object);
var consoleRepository = _container.Resolve<IConsoleRepository>();
SaveTestSubmission(consoleRepository);
_submissionModule =
_container.Resolve<SubmissionModule>(new ParameterOverride("currentHttpContext", _currentHttpContext),
new ParameterOverride("subscribeService", _mockSubscribeService));
}
示例5: InitializeContainer
private void InitializeContainer()
{
container = new UnityContainer();
container.AddNewExtension<Interception>();
container.RegisterType<BusinessLogic.BankAccount>(
new InterceptionBehavior<PolicyInjectionBehavior>(),
new Interceptor<TransparentProxyInterceptor>());
container.Configure<Interception>()
.AddPolicy("policy-updates")
.AddMatchingRule<TypeMatchingRule>(
new InjectionConstructor(
new InjectionParameter(typeof(BusinessLogic.BankAccount))))
.AddMatchingRule<MemberNameMatchingRule>(
new InjectionConstructor(
new InjectionParameter(new string[] { "Deposit", "Withdraw" })))
.AddCallHandler<TraceCallHandler>(
new ContainerControlledLifetimeManager(),
new InjectionConstructor(
new TraceSource("interception-updates")))
.Interception
.AddPolicy("policy-query")
.AddMatchingRule<TypeMatchingRule>(
new InjectionConstructor(
new InjectionParameter(typeof(BusinessLogic.BankAccount))))
.AddMatchingRule<MemberNameMatchingRule>(
new InjectionConstructor("GetCurrentBalance"))
.AddCallHandler<TraceCallHandler>(
new ContainerControlledLifetimeManager(),
new InjectionConstructor(
new TraceSource("interception-queries")));
}
示例6: RegisterTypes
public static void RegisterTypes(IUnityContainer container)
{
string[] assemblyNameParts = Assembly.GetExecutingAssembly().GetName().Name.Split('.');
string assemblyPrefix = string.Join(".", assemblyNameParts, 0, 1);
container.AddNewExtension<Interception>();
Predicate<Type> intercept = (t) =>
{
var interceptionConfiguration = container.Configure<Interception>();
if (t.IsConcrete() && !t.IsSealed && hasAttribute(t, typeof(LogAttribute)))
{
interceptionConfiguration.SetDefaultInterceptorFor(t, new VirtualMethodInterceptor());
}
return true;
};
Predicate<Assembly> includeAssembly = (a) =>
{
var assemblyName = a.GetName().Name;
return assemblyName.StartsWith(assemblyPrefix) && (assemblyName.Contains("Business") || assemblyName.Contains("Data"));
};
container.Configure(c =>
{
c.Scan(scan =>
{
scan.AssembliesInBaseDirectory(a => includeAssembly(a));
scan.Include(t => intercept(t));
scan.WithNamingConvention();
});
c.Configure<IDatabaseControlContext>().Using<HttpContextLifetimeManager<IDatabaseControlContext>>();
});
}
示例7: UnityCacheEnabledTests
public UnityCacheEnabledTests()
{
_container = new UnityContainer();
//Register interception
_container.AddNewExtension<Interception>();
//Register xCache
_container.RegisterType<ICache, MemoryCache>(new ContainerControlledLifetimeManager());
_container.RegisterType<ICache, MemoryCache>("One", new ContainerControlledLifetimeManager());
_container.RegisterType<ICache, MemoryCache>("Two", new ContainerControlledLifetimeManager());
_container.RegisterType<ICache, DictionaryCache>("DictionaryCache", new ContainerControlledLifetimeManager());
_container.RegisterType<ICacheKeyGenerator,JsonCacheKeyGenerator>(new ContainerControlledLifetimeManager());
_container.RegisterType<IDurableCacheQueue, TimedDurableCacheQueue>(
new ContainerControlledLifetimeManager(),
new InjectionFactory((c) => new TimedDurableCacheQueue(c.Resolve<IDurableCacheRefreshHandler>(), new TimeSpan(0,0,30))));
_container.RegisterType<IDurableCacheRefreshHandler, UnityDurableCacheRefreshHandler>(new ContainerControlledLifetimeManager());
//Register test class with interception
_container.RegisterType<ICacheEnableObject, UnityCacheEnabledObject>(
new InterceptionBehavior<PolicyInjectionBehavior>(),
new Interceptor<InterfaceInterceptor>());
_cached = _container.Resolve<ICacheEnableObject>();
}
示例8: ViewModelLocator
static ViewModelLocator()
{
BudgetMonitoringContainer = new UnityContainer();
BudgetMonitoringContainer.AddNewExtension<Interception>();
BudgetMonitoringContainer.RegisterType<BudgetMonitoringViewModel>().Configure<Interception>().SetInterceptorFor<BudgetMonitoringViewModel>(new VirtualMethodInterceptor());
BankAccountContainer = new UnityContainer();
BankAccountContainer.AddNewExtension<Interception>();
BankAccountContainer.RegisterType<BankAccountViewModel>().Configure<Interception>().SetInterceptorFor<BankAccountViewModel>(new VirtualMethodInterceptor());
CategoryContainer = new UnityContainer();
CategoryContainer.AddNewExtension<Interception>();
CategoryContainer.RegisterType<CategoryViewModel>().Configure<Interception>().SetInterceptorFor<CategoryViewModel>(new VirtualMethodInterceptor());
TransferContainer = new UnityContainer();
TransferContainer.AddNewExtension<Interception>();
TransferContainer.RegisterType<TransferViewModel>().Configure<Interception>().SetInterceptorFor<TransferViewModel>(new VirtualMethodInterceptor());
RegistrationContainer = new UnityContainer();
RegistrationContainer.AddNewExtension<Interception>();
RegistrationContainer.RegisterType<RegistrationViewModel>().Configure<Interception>().SetInterceptorFor<RegistrationViewModel>(new VirtualMethodInterceptor());
MainContainer = new UnityContainer();
MainContainer.AddNewExtension<Interception>();
MainContainer.RegisterType<MainViewModel>(new ContainerControlledLifetimeManager()).Configure<Interception>().SetInterceptorFor<MainViewModel>(new VirtualMethodInterceptor());
}
示例9: RegisterContainer
public static void RegisterContainer(IUnityContainer uc)
{
Log.Information("Begin Unity registration", CallerInfo.Create(), "");
uc.AddNewExtension<SimpleEventBrokerExtension>();
uc.RegisterType<FrmCertificate>();
uc.RegisterType<SendPOCController>();
uc.RegisterType<SendPOCViewmodel>();
uc.RegisterType<CertificateController>();
uc.RegisterType<CertificateViewModel>();
uc.RegisterType<IAddressBookModel, AddressBookModel>();
uc.RegisterType<eZustellServiceBase>(new ContainerControlledLifetimeManager());
uc.RegisterType<IeZustellService, eZustellService>(new ContainerControlledLifetimeManager());
uc.RegisterType<IRegistrationService, RegistrationService>(new ContainerControlledLifetimeManager());
uc.RegisterType<ICertificateService, CertificateService>(new ContainerControlledLifetimeManager());
uc.RegisterType<FrmLoadSaveCertificate>();
uc.RegisterType<LoadCertificateController>();
uc.RegisterType<LoadCertificateViewModel>();
uc.RegisterType<LoadSaveCertificateController>();
uc.RegisterType<LoadSaveCertificateViewModel>();
uc.RegisterType<SavePkcs12Controller>();
uc.RegisterType<SavePkcs12ViewModel>();
uc.RegisterType<SaveCertificateViewModel>();
uc.RegisterType<SaveCertificateController>();
uc.RegisterType<FrmAboutView>();
uc.RegisterType<AboutViewController>();
uc.RegisterType<AboutViewModel>();
}
示例10: SetupContainer
public static void SetupContainer()
{
// Create User
var user = new CurrentUser() { Username = "GDP1", LabCode = "EUHAWE3" };
// Create Logger
var logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.MinimumLevel.Warning() // Set MinimumLevel of Warning
.WriteTo.Seq("http://localhost:5341")
.CreateLogger();
unityContainer = new UnityContainer();
// Register User
unityContainer.RegisterInstance<ICurrentUser>(user);
// Add Interception Extension
unityContainer.AddNewExtension<Microsoft.Practices.Unity.InterceptionExtension.Interception>();
//Register Logger Instance
unityContainer.RegisterInstance<ILogger>(logger);
unityContainer.RegisterType<ISamRepository, SamRepository>()
.Configure<Microsoft.Practices.Unity.InterceptionExtension.Interception>()
.SetInterceptorFor<ISamRepository>(
new InterfaceInterceptor());
}
示例11: Init
public void Init()
{
Container = new UnityContainer();
Container.AddNewExtension<EnterpriseLibraryCoreExtension>();
Container.RegisterType<ILogHandler, LogHandler>();
Container.RegisterType<IConsoleRepository, ConsoleRepository>();
var mockCurrentHttpContext = new Mock<ICurrentHttpContext>();
var user = @"talbotdev\MurrayE";
user = user.Replace(@"\\", @"\");
mockCurrentHttpContext.Setup(h => h.CurrentUser).Returns(new GenericPrincipal(new GenericIdentity(user), null));
mockCurrentHttpContext.Setup(h => h.Context).Returns(MvcMockHelpers.FakeHttpContextWithSession());
var currentHttpContext = mockCurrentHttpContext.Object;
var mockSubscribeService = new Mock<IPolicyService>();
IPolicyService subscribeService = mockSubscribeService.Object;
IPolicyData policyData = Container.Resolve<PolicyData>(new ParameterOverride("currentHttpContext", currentHttpContext));
IWebSiteModuleManager webSiteModuleManager = Container.Resolve<WebSiteModuleManager>(new ParameterOverride("currentHttpContext", currentHttpContext));
PolicyBusinessModule = Container.Resolve<PolicyBusinessModule>(
new ParameterOverride("policyData", policyData),
new ParameterOverride("subscribeService", subscribeService),
new ParameterOverride("webSiteModuleManager", webSiteModuleManager));
}
开发者ID:Eugene-Murray,项目名称:Contract_Validus,代码行数:26,代码来源:PolicyBusinessModuleIntegrationTestFixture.cs
示例12: RegisterTypes
/// <summary>WebARMters the type mappings with the Unity container.</summary>
/// <param name="container">The unity container to configure.</param>
/// <remarks>There is no need to WebARMter concrete types such as controllers or API controllers (unless you want to
/// change the defaults), as Unity allows resolving a concrete type even if it was not previously WebARMtered.</remarks>
public static void RegisterTypes(IUnityContainer container)
{
// NOTE: To load from web.config uncomment the line below. Make sure to add a Microsoft.Practices.Unity.Configuration to the using statements.
// container.LoadConfiguration();
// TODO: WebARMter your types here
container.RegisterType<IBaseRepository, BaseRepository>();
container.RegisterType<IGeneralSettingsRepository, GeneralSettingsRepository>();
container.RegisterType<IInfoChangeFileRepository, InfoChangeFileRepository>();
container.RegisterType<ILocalService, LocalService>();
container.RegisterType<IUserServiceProxy, UserServiceProxy>();
container.RegisterType<IUserCommitServiceProxy, UserCommitServiceProxy>();
container.RegisterType<IMainRepositoryServiceProxy, MainRepositoryServiceProxy>();
container.RegisterType<CreateCommand>();
container.RegisterType<UseCommand>();
container.RegisterType<ShowCommand>();
container.RegisterType<CommitCommand>();
container.RegisterType<IVCSmyServerService>("base", new InjectionFactory(c => WCFCannelFactory.Create()));
container.AddNewExtension<Interception>();
container.RegisterType<IVCSmyServerService>(
new InjectionFactory(c => container.Resolve<IVCSmyServerService>("base")),
new Interceptor<InterfaceInterceptor>(),
new InterceptionBehavior<WCFProxyInterceptor>());
container.RegisterType<IServer, Server>();
}
示例13: InitializeContainer
private void InitializeContainer()
{
container = new UnityContainer();
container.AddNewExtension<Interception>();
container.RegisterType<BusinessLogic.BankAccount>(
new Interceptor<VirtualMethodInterceptor>(),
new InterceptionBehavior(new TraceBehavior(new TraceSource("interception"))));
}
示例14: InitializeContainer
private void InitializeContainer()
{
container = new UnityContainer();
container.AddNewExtension<Interception>();
container.RegisterType<BusinessLogic.BankAccount>(
new InterceptionBehavior<PolicyInjectionBehavior>(),
new Interceptor<TransparentProxyInterceptor>());
}
示例15: Init
public void Init()
{
_container = new UnityContainer();
_container.AddNewExtension<EnterpriseLibraryCoreExtension>();
_logHandler = _container.Resolve<LogHandler>();
// Note: this path is also set in "Rolling Flat File Trace Listener" section
_logFileLocation = ConfigurationManager.AppSettings["logFileLocation"].ToString();
}