本文整理汇总了C#中ServiceContainer类的典型用法代码示例。如果您正苦于以下问题:C# ServiceContainer类的具体用法?C# ServiceContainer怎么用?C# ServiceContainer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServiceContainer类属于命名空间,在下文中一共展示了ServiceContainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ChildContainerShouldBeDisposed
public void ChildContainerShouldBeDisposed()
{
var ioc = new ServiceContainer();
var childContainer = ioc.CreateChildContainer();
ioc.Dispose();
Assert.That(() => childContainer.Clear(), Throws.TypeOf(typeof(ObjectDisposedException)));
}
示例2: EnableLightInject
public static IServiceContainer EnableLightInject(this HttpConfiguration configuration)
{
var container = new ServiceContainer();
container.RegisterApiControllers();
container.EnableWebApi(configuration);
return container;
}
示例3: Main
public static void Main(string[] args)
{
var argumentParser = ApplicationArgumentsConfigurationSetup.CreateCommandLineParser();
ICommandLineParserResult parseResult = argumentParser.Parse(args);
if (!parseResult.HasErrors && !parseResult.EmptyArgs)
{
using (var serviceContainer = new ServiceContainer())
{
serviceContainer.RegisterFrom<CompositionRoot>();
IFileSystemMonitorServiceFactory factory = serviceContainer.GetInstance<IFileSystemMonitorServiceFactory>(CompositionRoot.LoggingFileSystemMonitorServiceFactory);
FileSystemMonitorServiceConfiguration configuration = CreateConfiguration(argumentParser.Object);
var logger = serviceContainer.GetInstance<ILogger>();
logger.Log(LogLevel.Trace, "From: {0} To: {1}", configuration.FolderToMonitor, configuration.TargetFolder);
FileSystemMonitorService service = factory.Create(configuration);
ServiceBase.Run(service);
}
}
else
{
argumentParser.HelpOption.ShowHelp(argumentParser.Options);
}
}
示例4: InitializeLightInject
private static void InitializeLightInject(HttpConfiguration config)
{
var container = new ServiceContainer();
container.RegisterFrom<Composition.CompositionModule>();
container.RegisterApiControllers();
container.EnableWebApi(config);
}
示例5: Scan_HostAssembly_DoesNotConfigureInternalServices
public void Scan_HostAssembly_DoesNotConfigureInternalServices()
{
var container = new ServiceContainer();
container.RegisterAssembly(typeof(ServiceContainer).Assembly);
var result = container.AvailableServices.Where(si => si.ImplementingType.Namespace == "LightInject");
Assert.IsFalse(container.AvailableServices.Any(si => si.ImplementingType != null && si.ImplementingType.Namespace == "LightInject"));
}
示例6: Main
static void Main(string[] args)
{
MongoDBRepository.RegisterMongoDBContext(new TripperCenterDBContext());
MongoDBRepository.RegisterMongoDBContext(new DeliveryCenterDBContext());
MongoDBRepository.RegisterMongoDBContext(new StatusCenterDBContext());
MongoDBRepository.RegisterMongoDBContext(new RelationCenterDBContext());
MongoDBRepository.RegisterMongoIndex();
var ass = WinAssemblyUtility.GetAssembly();
HostInfo host = new HostInfo(ConfigurationManager.AppSettings["WcfHostAddress"]).LoadTypesFromAssemblies(ass);
using (ServiceContainer container = new ServiceContainer())
{
container.Open(host);
Console.WriteLine("press close to stop host");
while (true)
{
if ("close" == Console.ReadLine().ToLower())
{
container.Close(host);
break;
}
}
Console.WriteLine("press 'Enter' to quit");
Console.ReadKey();
}
}
示例7: Main
static void Main(string[] args)
{
Console.WriteLine("Start");
var container = new ServiceContainer();
container.Register<IDataBaseController, DataBaseController>();
IDataBaseController _dbController = container.GetInstance<IDataBaseController>();
Product p1 = new Product()
{
Id = 1
};
Product p2 = new Product()
{
Id = 2
};
Product p3 = null;
_dbController.InsertProduct(p1);
_dbController.InsertProduct(p3);
_dbController.InsertProduct(p2);
Console.WriteLine("End");
Console.ReadLine();
}
示例8: Register
public static void Register(ServiceContainer container)
{
container.Register<IBotManager, BotManager>();
container.Register<IMessageHandler, MessageHandler>();
container.Register<ICommandHelper, CommandHelper>();
DataDependenciesConfig.Register(container);
}
示例9: RegisterFactory_WithCompositionRoot_ShouldBeNotNull
public void RegisterFactory_WithCompositionRoot_ShouldBeNotNull()
{
var container = new ServiceContainer();
var directory = AppDomain.CurrentDomain.BaseDirectory;
var finder = AssemblyFinder.Builder.UsePath(directory).Create;
container.RegisterFrom<ServiceLocatorCompositionRoot>();
var assemblies = finder.GetAssembliesTagged<AssemblyTagAttribute>();
container.RegisterFactory(assemblies);
container.Register<IDoSomething, DoSomething>(typeof(DoSomething).FullName);
var instance = container.GetInstance<IObjectFactory>();
instance.ShouldNotBeNull();
instance.ConfigurationProvider.Configuration.Items.ShouldNotBeEmpty();
instance.ConfigurationProvider.Configuration.Items.Count.ShouldBe(1);
instance.ConfigurationProvider.Sources.ShouldNotBeEmpty();
instance.ConfigurationProvider.Sources.Length.ShouldBe(2);
instance.ShouldBeAssignableTo<IObjectFactory>();
instance.ShouldBeOfType<ObjectFactory>();
}
示例10: RegisterContainer
private void RegisterContainer()
{
var container = new ServiceContainer();
container.RegisterApiControllers();
container.RegisterFrom<CompositionRoot>();
container.EnableWebApi(this);
}
示例11: LoadContentArgs
//monoFrameworkAlias.Microsoft.Xna.Framework.Graphics.GraphicsDevice monoDevice)
//public monoFrameworkAlias.Microsoft.Xna.Framework.Graphics.GraphicsDevice MonoDevice { get; private set; }
public LoadContentArgs(GraphicsDevice device, GraphicsDeviceService graphicsService, ServiceContainer services)
{
GraphicsDevice = device;
GraphicsService = graphicsService;
Services = services;
//MonoDevice = monoDevice;
}
示例12: MoveCreatorForm
public MoveCreatorForm()
{
//set up defaults
this.movelist = new Dictionary<String, Move>();
this.directoryHome = "../../../HeroesOfRock";
this.FormClosing += ContentList_FormClosing; ;
this.appClose = true;
//set up content manager
GraphicsDeviceService gds = GraphicsDeviceService.AddRef(this.Handle,
this.ClientSize.Width, this.ClientSize.Height);
ServiceContainer services = new ServiceContainer();
services.AddService<IGraphicsDeviceService>(gds);
this.content = new ContentManager(services, String.Concat(directoryHome, "/HeroesOfRock/bin/x86/Debug/Content"));
//Load and/or parse predefined objects
LoadMoveList(content.Load<Move[]>("Movelist"));
this.audioClips = Directory.GetFiles(String.Concat(content.RootDirectory, "/Audio")).ToList<string>();
this.particleFX = Directory.GetFiles(String.Concat(content.RootDirectory, "/ParticleFX")).ToList<string>();
//if null, will back up to the content default
BackUpMoveList(null);
InitializeComponent();
RefreshList();
}
示例13: GetInstance_NoServices_CallsAssemblyScannerOnlyOnce
public void GetInstance_NoServices_CallsAssemblyScannerOnlyOnce()
{
var scannerMock = new Mock<IAssemblyScanner>();
var serviceContainer = new ServiceContainer();
serviceContainer.AssemblyScanner = scannerMock.Object;
try
{
serviceContainer.GetInstance<IFoo>();
}
catch
{
try
{
serviceContainer.GetInstance<IFoo>();
}
catch
{
}
}
finally
{
scannerMock.Verify(a => a.Scan(typeof(IFoo).Assembly, It.IsAny<IServiceRegistry>(), LifeCycleType.Transient, It.IsAny<Func<Type, bool>>()), Times.Once());
}
}
示例14: Create_WithCustomerOlderThan25_ShouldBeNotEmpty
public void Create_WithCustomerOlderThan25_ShouldBeNotEmpty()
{
var container = new ServiceContainer();
var directory = AppDomain.CurrentDomain.BaseDirectory;
var finder = AssemblyFinder.Builder.UsePath(directory).Create;
container.RegisterFrom<ServiceLocatorCompositionRoot>();
var assemblies = finder.GetAssembliesTagged<AssemblyTagAttribute>();
container.RegisterFactory(assemblies);
container.Register<IDoSomething, DoSomething>(typeof(DoSomething).FullName);
var factory = container.GetInstance<IObjectFactory>();
var customer = new Customer(){Age = 25};
var services = factory.Create<Customer, IDoSomething>(customer);
services.ShouldNotBeEmpty();
services.Length.ShouldBe(1);
services[0].ShouldBeAssignableTo<IDoSomething>();
services[0].ShouldBeOfType<DoSomething>();
}
示例15: InitializeServices
/// <summary>
/// Инициализатор сервисов.
/// </summary>
/// <param name="sysInfo">Информация о системе.</param>
/// <param name="container">Сервисы.</param>
public static void InitializeServices(ServiceContainer container, SystemInfoParam sysInfo)
{
container.RegisterService<IRegexCacheService>(new RegexCacheService(container));
container.RegisterService<IYoutubeIdService>(new YoutubeIdService(container));
container.RegisterService<IDateService>(new DateService(container));
container.RegisterService<ICaptchaService>(new CaptchaService(container));
container.RegisterService<ILinkHashService>(new LinkHashService(container));
container.RegisterService<ISerializerCacheService>(new SerializerCacheService(container));
container.RegisterService<IStorageService>(new StorageService(container));
container.RegisterService<ILinkTransformService>(new LinkTransformService(container));
container.RegisterService<INetworkLogic>(new NetworkLogicService(container));
container.RegisterService<ISystemInfo>(new SystemInfo(container, sysInfo));
container.RegisterService<IThreadTreeProcessService>(new ThreadTreeProcessService(container));
container.RegisterService<ILiveTileService>(new LiveTileService(container));
container.RegisterService<IJsonService>(new JsonService(container));
container.RegisterService<IYoutubeUriService>(new YoutubeUriService(container));
container.RegisterService<IApiKeyService>(new ApiKeyService(container));
container.RegisterService<INavigationKeyService>(new NavigationKeyService(container));
container.RegisterService<IBoardLinkKeyService>(new BoardLinkKeyService(container));
container.RegisterService<IMarkupService>(new MarkupService(container));
var engines = new NetworkEngines(container);
container.RegisterService<INetworkEngines>(engines);
container.RegisterService<INetworkEngineInstaller>(engines);
}