本文整理汇总了C#中Microsoft.Practices.Unity.UnityContainer类的典型用法代码示例。如果您正苦于以下问题:C# UnityContainer类的具体用法?C# UnityContainer怎么用?C# UnityContainer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnityContainer类属于Microsoft.Practices.Unity命名空间,在下文中一共展示了UnityContainer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Register
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Configure Web API to use only bearer token authentication.
config.SuppressDefaultHostAuthentication();
config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
//Unity
var container = new UnityContainer();
container.RegisterType<IUnitOfWork, UnitOfWork>(new HierarchicalLifetimeManager());
container.RegisterType<IGenericRepository<Farmacia>, GenericRepository<Farmacia>>(new HierarchicalLifetimeManager());
config.DependencyResolver = new UnityResolver(container);
//Formatters
config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
//GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
//config.Formatters.Insert(0, new System.Net.Http.Formatting.JsonMediaTypeFormatter());
// Web API routes
config.MapHttpAttributeRoutes();
//config.EnableCors();
var cors = new EnableCorsAttribute("http://localhost:28285", "*", "*");
config.EnableCors(cors);
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
开发者ID:RubenGomes10,项目名称:Farma,代码行数:30,代码来源:WebApiConfig.cs
示例2: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
IUnityContainer container = new UnityContainer();
UnityConfigurationSection section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
section.Configure(container);
if (Request["installation"] != null)
{
int installationid = Int32.Parse(Request["installation"]);
userid = Int32.Parse(Request["userid"]);
user = Request["user"];
sservice = container.Resolve<IStatisticService>();
IInstallationBL iinstall = container.Resolve<IInstallationBL>();
imodel = iinstall.getInstallation(installationid);
Dictionary<InstallationModel, List<InstallationState>> statelist = sservice.getInstallationState(imodel.customerid);
StringBuilder str = new StringBuilder();
str.Append("<table border = '1'><tr><th>Description</th><th>Messwert</th><th>Einheit</th></tr>");
foreach (var values in statelist)
{
if(values.Key.installationid.Equals(installationid))
{
foreach (var item in values.Value)
{
str.Append("<tr><td>" + item.description + "</td><td>" + item.lastValue + "</td><td>" + item.unit + "</td></tr>");
}
break;
}
}
str.Append("</table>");
anlagenzustand.InnerHtml = str.ToString();
}
}
开发者ID:daniel9992000,项目名称:bif5-sks-csharp,代码行数:31,代码来源:InstallationDetail.aspx.cs
示例3: RegisterComponents
public static void RegisterComponents()
{
var container = new UnityContainer();
// register all your components with the container here
// it is NOT necessary to register your controllers
// e.g. container.RegisterType<ITestService, TestService>();
GlobalConfiguration.Configuration.DependencyResolver = new UnityDependencyResolver(container);
// repositories injection
container.RegisterType<IRepository<Item, int>, ItemRepository>();
container.RegisterType<IRepository<Category, int>, CategoryRepository>();
container.RegisterType<IRepository<Reservation, int>, ReservationRepository>();
container.RegisterType<IRepository<Image, int>, ImageRepository>();
// authentication injection
container.RegisterType<DbContext, ReservationContext>(new HierarchicalLifetimeManager());
container.RegisterType<UserManager<User>, ApplicationUserManager>();
container.RegisterType<ReservationContext>(new HierarchicalLifetimeManager());
container.RegisterType<ApplicationUserManager>();
container.RegisterType<ISecureDataFormat<AuthenticationTicket>, SecureDataFormat<AuthenticationTicket>>();
container.RegisterType<ITextEncoder, Base64TextEncoder>();
container.RegisterType<IDataSerializer<AuthenticationTicket>, TicketSerializer>();
container.RegisterType<IDataProtector>(new InjectionFactory(o => new DpapiDataProtectionProvider().Create("ASP.NET Identity")));
container.RegisterType<IUserStore<User>, UserStore<User>>(new InjectionConstructor(typeof(ReservationContext)));
container.RegisterType<IAuthenticationManager>(new InjectionFactory(o => HttpContext.Current.GetOwinContext().Authentication));
container.RegisterType<IOwinContext>(new InjectionFactory(o => HttpContext.Current.GetOwinContext()));
}
开发者ID:mikolajtr,项目名称:reservations,代码行数:31,代码来源:UnityConfig.cs
示例4: LoginUser
public static string LoginUser(string username, string password, string response)
{
string result = string.Empty;
try
{
if (!IsRobot(response))
{
IUnityContainer container = new UnityContainer();
container.RegisterType<AccountMgr>();
container.RegisterType<IAccountDacMgr, AccountDacMgr>();
AccountMgr accountMgr = container.Resolve<AccountMgr>();
accountMgr.UserName = username;
accountMgr.Password = password;
if (accountMgr.Login())
{
FormsAuthentication.SetAuthCookie(accountMgr.UserName, false);
result = "OK";
}
}
}
catch
{
throw;
}
return result;
}
开发者ID:wjkong,项目名称:ApiExpert,代码行数:32,代码来源:Login.aspx.cs
示例5: BuildUnityContainer
private static IUnityContainer BuildUnityContainer()
{
var container = new UnityContainer();
// Register repository.
container.RegisterType<IMyBigBroRepository, MyBigBroRepository>(
new InjectionConstructor(new MyBigBroContext(GetConnectionString())));
// Register services.
container.RegisterType<ILocation, Location>();
container.RegisterType<IStorageServiceAgent, AzureStorageServiceAgent>();
container.RegisterType<ILocation, Location>();
container.RegisterType<IWebCamControl, WebCamControl>();
container.RegisterType<IGeoMarkerService, GeoMarkerService>();
container.RegisterType<IAccountService, AccountService>();
container.RegisterType<IFormsAuthenticationService, FormsAuthenticationService>();
// Register Web API controllers.
//container.RegisterType<LoginController>();
container.RegisterType<GeoMarkersController>();
container.RegisterType<CapturedImagesGeoMarkerController>();
container.RegisterType<WebCamsController>();
// Return the populated container.
return container;
}
开发者ID:bernardoleary,项目名称:MyBigBro,代码行数:26,代码来源:Bootstrapper.cs
示例6: TryResolveShouldReturnNullIfElementNotExist
public void TryResolveShouldReturnNullIfElementNotExist()
{
var container = new UnityContainer();
object dependantA = container.TryResolve<IDependantA>();
Assert.IsNull(dependantA);
}
开发者ID:ValdimarThor,项目名称:Prism,代码行数:7,代码来源:UnityContainerExtensionFixture.cs
示例7: BuildUnityContainer
private static IUnityContainer BuildUnityContainer()
{
var container = new UnityContainer();
container.RegisterType<IHomeService, HomeService>();
MvcUnityContainer.Container = container;
return container;
}
开发者ID:cbsistem,项目名称:Kitto-1,代码行数:7,代码来源:Bootstrapper.cs
示例8: AsyncMain
static async Task AsyncMain()
{
#region ContainerConfiguration
BusConfiguration busConfiguration = new BusConfiguration();
busConfiguration.EndpointName("Samples.Unity");
UnityContainer container = new UnityContainer();
container.RegisterInstance(new MyService());
busConfiguration.UseContainer<UnityBuilder>(c => c.UseExistingContainer(container));
#endregion
busConfiguration.UseSerialization<JsonSerializer>();
busConfiguration.UsePersistence<InMemoryPersistence>();
busConfiguration.EnableInstallers();
busConfiguration.SendFailedMessagesTo("error");
IEndpointInstance endpoint = await Endpoint.Start(busConfiguration);
try
{
IBusSession busSession = endpoint.CreateBusSession();
await busSession.SendLocal(new MyMessage());
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
finally
{
await endpoint.Stop();
}
}
开发者ID:cdnico,项目名称:docs.particular.net,代码行数:28,代码来源:Program.cs
示例9: BuildUnityContainer
private static IUnityContainer BuildUnityContainer()
{
var container = new UnityContainer();
container.LoadConfiguration();
return container;
}
开发者ID:jesusmoreno85,项目名称:LoginTestApp,代码行数:7,代码来源:Bootstrapper.cs
示例10: Register
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
//
var container = new UnityContainer();
//Service registration
container.RegisterType<ITestService, TestService>(new HierarchicalLifetimeManager());
//Data repository registration
container.RegisterType<ITestRepo, TestRepo>(new HierarchicalLifetimeManager());
config.DependencyResolver = new UnityDiResolver(container);
// Web API routes - attribute routing
//
config.MapHttpAttributeRoutes();
// Web API routes - conventional routing
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
开发者ID:bob1457,项目名称:WBooking,代码行数:29,代码来源:WebApiConfig.cs
示例11: Register
public static void Register(HttpConfiguration config)
{
// Dependency resolver for dependency injection
UnityContainer container = new UnityContainer();
container.RegisterType<IResearchRepository, ResearchRepository>(new HierarchicalLifetimeManager());
container.RegisterType<IProjectsRepository, ProjectsRepository>(new HierarchicalLifetimeManager());
container.RegisterType<IReferencesRepository, ReferencesRepository>(new HierarchicalLifetimeManager());
config.DependencyResolver = new UnityResolver(container);
config.MapHttpAttributeRoutes();
// API routes
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional });
//OData Models
ODataModelBuilder odataBuilder = new ODataConventionModelBuilder();
odataBuilder.Namespace = "SpResearchTracker.Models";
odataBuilder.EntitySet<Project>("Projects");
odataBuilder.EntitySet<Reference>("References");
// OData routes
config.Routes.MapODataRoute(
routeName: "odata",
routePrefix: "odata",
model: odataBuilder.GetEdmModel(),
batchHandler: new BreezeODataBatchHandler(GlobalConfiguration.DefaultServer));
}
开发者ID:ruperthulme,项目名称:Research-Project-Code-Sample,代码行数:30,代码来源:WebApiConfig.cs
示例12: Register
public void Register(UnityContainer container)
{
container
.ConfigureAutoRegistration()
.Include(x => x.Assembly == Assembly.GetExecutingAssembly(), Then.Register().AsAllInterfacesOfType().UsingPerCallMode())
.ApplyAutoRegistration();
}
开发者ID:swmal,项目名称:DiIocDemo,代码行数:7,代码来源:RegisterAllModule.cs
示例13: Application_Start
/// <summary>
/// Application Entry Point
/// </summary>
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
//*************************************************************
AppDomain.CurrentDomain.UnhandledException +=
delegate(object sender, UnhandledExceptionEventArgs e)
{
Logging.LogManagerProvider.Instance.WriteError(e.ExceptionObject as Exception);
};
//logging initialization
Logging.LogManagerProvider.Initialize("LoggingSection");
//Repository and controller initialization
UnityContainer container = new UnityContainer();
RepositoryProvider.Register(container, "RepositoryProvider");
GlobalConfiguration.Configuration.DependencyResolver = new Unity.WebApi.UnityDependencyResolver(container);
//*************************************************************
}
开发者ID:spbuksh,项目名称:CuratedGalleries,代码行数:28,代码来源:Global.asax.cs
示例14: RegisterUnityContainer
private UnityContainer RegisterUnityContainer()
{
var container = new UnityContainer();
container.LoadConfiguration();
return container;
}
开发者ID:fanshu,项目名称:CoursewareDI,代码行数:7,代码来源:Global.asax.cs
示例15: Resolve
public static void Resolve(UnityContainer container)
{
container.RegisterType<DataBaseContext, DataBaseContext>(new HierarchicalLifetimeManager());
container.RegisterType<IUsuarioService, UsuarioService>(new HierarchicalLifetimeManager());
container.RegisterType<IUsuarioRepository, UsuarioRepository>(new HierarchicalLifetimeManager());
container.RegisterType<IPermissaoRepository, PermissaoRepository>(new HierarchicalLifetimeManager());
container.RegisterType<IGrupoPermissaoRepository, GrupoPermissaoRepository>(new HierarchicalLifetimeManager());
container.RegisterType<IAutenticacao, AutenticacaoService>(new HierarchicalLifetimeManager());
container.RegisterType<IPessoaService, PessoaService>(new HierarchicalLifetimeManager());
container.RegisterType<IPessoaRepository, PessoaRepository>(new HierarchicalLifetimeManager());
container.RegisterType<IPapelRepository, PapelRepository>(new HierarchicalLifetimeManager());
container.RegisterType<IPessoaFisicaRepository, PessoaFisicaRepository>(new HierarchicalLifetimeManager());
container.RegisterType<IPessoaJuridicaRepository, PessoaJuridicaRepository>(new HierarchicalLifetimeManager());
container.RegisterType<IMeioComunicacaoRepository, MeioComunicacaoRepository>(new HierarchicalLifetimeManager());
container.RegisterType<IEnderecoRepository, EnderecoRepository>(new HierarchicalLifetimeManager());
container.RegisterType<IEstadoCivilRepository, EstadoCivilRepository>(new HierarchicalLifetimeManager());
container.RegisterType<IEstadoRepository, EstadoRepository>(new HierarchicalLifetimeManager());
container.RegisterType<IProdutoService, ProdutoService>(new HierarchicalLifetimeManager());
container.RegisterType<IProdutoRepository, ProdutoRepository>(new HierarchicalLifetimeManager());
container.RegisterType<IUnidadeRepository, UnidadeRepository>(new HierarchicalLifetimeManager());
container.RegisterType<ICondicaoPagamentoService, CondicaoPagamentoService>(new HierarchicalLifetimeManager());
container.RegisterType<IFormaPagamentoService, FormaPagamentoService>(new HierarchicalLifetimeManager());
container.RegisterType<ICondicaoPagamentoRepository, CondicaoPagamentoRepository>(new HierarchicalLifetimeManager());
container.RegisterType<IFormaPagamentoRepository, FormaPagamentoRepository>(new HierarchicalLifetimeManager());
//container.RegisterType<User, User>(new HierarchicalLifetimeManager());
}
开发者ID:felipeffs6,项目名称:RepositorioGitProjetoArtCouro,代码行数:30,代码来源:DependencyResolver.cs
示例16: 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);
}
}
开发者ID:jcme,项目名称:Sample-MVC,代码行数:26,代码来源:LazyTest.cs
示例17: InjectClassWithTwoConstructors
public void InjectClassWithTwoConstructors()
{
int myInt = 37;
string myStr = "Test";
IUnityContainer container = new UnityContainer();
//constructor without params
container.Configure<InjectedMembers>().ConfigureInjectionFor<TestClass>(new InjectionConstructor());
TestClass withOutCon = container.Resolve<TestClass>();
Assert.IsFalse(withOutCon.StringConstructorCalled);
Assert.IsFalse(withOutCon.IntConstructorCalled);
//constructor with one param
container.Configure<InjectedMembers>()
.ConfigureInjectionFor<TestClass>("First",
new InjectionConstructor(myInt));
TestClass myTestClass = container.Resolve<TestClass>("First");
Assert.IsFalse(myTestClass.StringConstructorCalled);
Assert.IsTrue(myTestClass.IntConstructorCalled);
//constructor with one param
container.Configure<InjectedMembers>()
.ConfigureInjectionFor<TestClass>("Second",
new InjectionConstructor(myStr));
TestClass myTestClass1 = container.Resolve<TestClass>("Second");
Assert.IsFalse(myTestClass1.IntConstructorCalled);
Assert.IsTrue(myTestClass1.StringConstructorCalled);
}
开发者ID:CFMITL,项目名称:unity,代码行数:33,代码来源:InjectedMembersFixture.cs
示例18: Register
public static void Register(HttpConfiguration config)
{
// Web API configuration and services registration
var container = new UnityContainer();
var dataAccessRegistration = new DataAccessRegistration();
var repositoryRegistation = new RepositoryRegistration();
var serviceRegistration = new ServiceRegistration();
dataAccessRegistration.Register(container);
repositoryRegistation.Register(container);
serviceRegistration.Register(container);
config.DependencyResolver = new UnityResolver(container);
config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
config.Formatters.JsonFormatter.UseDataContractJsonSerializer = false;
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
开发者ID:ryansites310,项目名称:OptumSAG,代码行数:28,代码来源:WebApiConfig.cs
示例19: RegisterUnityContainer
private void RegisterUnityContainer()
{
var container = new UnityContainer();
container.RegisterType<IPkgOrderService, PkgOrderService>(new PerThreadLifetimeManager())
.RegisterType<IDALContext, PkgOrderDALContext>();
DependencyResolver.SetResolver(new UnityDependencyResolver(container));
}
开发者ID:Ericgan,项目名称:EF_RepositoryPattern,代码行数:7,代码来源:Global.asax.cs
示例20: Main
static void Main(string[] args)
{
using (UnityContainer container = new UnityContainer())
{
ContainerBootstrapper.RegisterTypes(container);
Application consoleApp = new Application();
consoleApp.Title = "WELCOME! This program will help you test the Files REST service.";
foreach (string commandType in new string[] {
"UploadCommand",
"GetAllMetadataCommand",
"GetMetadataCommand",
"DownloadAllCommand",
"DownloadCommand",
"DeleteCommand",
"SettingsCommand"
})
{
Commands.BaseCommand command = container.Resolve<Commands.BaseCommand>(commandType);
consoleApp.AddCommand(command);
}
Starter.Start(consoleApp);
}
}
开发者ID:gentisaliu,项目名称:webservice-examples,代码行数:26,代码来源:Program.cs
注:本文中的Microsoft.Practices.Unity.UnityContainer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论