本文整理汇总了C#中IContainer.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# IContainer.Dispose方法的具体用法?C# IContainer.Dispose怎么用?C# IContainer.Dispose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IContainer
的用法示例。
在下文中一共展示了IContainer.Dispose方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
public void Start()
{
_container = ConfigureContainer().Build();
HostFactory.Run(
x =>
{
x.RunAsLocalService();
_overidedServiceConfiguration(x);
x.UseAutofacContainer(_container);
x.Service<JobsManager>(
s =>
{
s.ConstructUsingAutofacContainer();
s.WhenStarted(tc => tc.Start());
s.WhenStopped(
tc =>
{
tc.Stop();
_container.Dispose();
});
ConfigureBackgroundJobs(s);
});
x.SetDescription(_serviceDescription);
x.SetDisplayName(_serviceDisplayName);
x.SetServiceName(_serviceName);
x.UseLog4Net();
});
}
示例2: StopService
private static void StopService(IWeatherService srv, IContainer container)
{
try
{
srv.Stop();
container.Dispose();
}
catch (Exception err)
{
EventLog.WriteEntry(Weatherservice, err.ToString(), EventLogEntryType.Error);
}
}
示例3: Main
private static int Main(string[] args)
{
Console.WriteLine("This sample demostrates how to integrate Quartz, TopShelf and Autofac.");
s_log.Info("Starting...");
try
{
_container = ConfigureContainer(new ContainerBuilder()).Build();
HostFactory.Run(conf =>
{
conf.SetServiceName("AutofacExtras.Quartz.Sample");
conf.SetDisplayName("Quartz.Net integration for autofac");
conf.UseLog4Net();
conf.UseAutofacContainer(_container);
conf.Service<ServiceCore>(svc =>
{
svc.ConstructUsingAutofacContainer();
svc.WhenStarted(o => o.Start());
svc.WhenStopped(o =>
{
o.Stop();
_container.Dispose();
});
ConfigureBackgroundJobs(svc);
});
});
s_log.Info("Shutting down...");
log4net.LogManager.Shutdown();
return 0;
}
catch (Exception ex)
{
s_log.Fatal("Unhandled exception", ex);
log4net.LogManager.Shutdown();
return 1;
}
}
示例4: Main
static int Main(string[] args)
{
s_log.Info("Starting...");
try
{
_container = ConfigureContainer(new ContainerBuilder()).Build();
HostFactory.Run(conf =>
{
conf.SetServiceName("VapoDataBus");
conf.SetDisplayName("Vaporize old DataBus folders");
conf.UseLog4Net();
conf.UseAutofacContainer(_container);
conf.Service<ServiceCore>(svc =>
{
svc.ConstructUsingAutofacContainer();
svc.WhenStarted(o => o.Start());
svc.WhenStopped(o =>
{
o.Stop();
_container.Dispose();
});
ConfigureBackgroundJobs(svc);
});
});
s_log.Info("Shutting down...");
log4net.LogManager.Shutdown();
return 0;
}
catch (Exception ex)
{
s_log.Fatal("Unhandled exception", ex);
log4net.LogManager.Shutdown();
return 1;
}
}
示例5: Main
//.........这里部分代码省略.........
.OnSuccess((ep, m) =>
{
Console.WriteLine("Get message {0} from {1}:{2}", m, ep.Address, ep.Port);
m.Sender.IpAddress = ep.Address;
_container.Resolve<HubblUsersService>().Add(m.Sender);
}).OnException(
e =>
{
Console.WriteLine("Exception catched!");
Console.WriteLine(" " + e.Message);
throw e;
});
;
router.Subscribe<TextMessage>()
.OnSuccess((rp, m) =>
{
var user = _container.Resolve<HubblUsersService>().Get(rp);
Console.WriteLine("{0}:{1}", user != null ? user.Title : Resources.UnknownUser, m.Text);
}).OnException(
e =>
{
Console.WriteLine("Exception catched!");
Console.WriteLine(" " + e.Message);
throw e;
});
;
router.Subscribe<AddCloudTrackMessage>()
.OnSuccess((rp, m) =>
{
Console.WriteLine("Cloud track request " + m.Track.Source);
var entry = _container.Resolve<IMusicPlayer>().QueueTrack(m.Sender, m.Track);
Console.WriteLine("added {0}", entry);
}).OnException(
e =>
{
Console.WriteLine("Exception catched!");
Console.WriteLine(" " + e.Message);
throw e;
});
router.Subscribe<SendFileMessage>()
.OnSuccess((rp, m) =>
{
Console.WriteLine("We got the file transfer! name: " + m.Filename);
Console.WriteLine(" Trying to save...");
var fileStream = File.Create("files/", (int) m.StreamLength);
var bytesInStream = new byte[(int) m.Stream.Length];
m.Stream.Read(bytesInStream, 0, bytesInStream.Length);
fileStream.Write(bytesInStream, 0, bytesInStream.Length);
}).OnException(
e =>
{
Console.WriteLine("Exception catched!");
Console.WriteLine(" " + e.Message);
throw e;
}).OnStart((m) =>
{
Console.WriteLine("We got the file transfer! on start!");
Console.WriteLine(" Trying to save...");
}
);
Task.Factory.StartNew(() => router.Start());
Console.CancelKeyPress += ConsoleOnCancelKeyPress;
_running = true;
var users = _container.Resolve<IUsersService>();
var player = _container.Resolve<IMusicPlayer>();
while (_running)
{
Console.Write("hubl>: ");
var commandLine = Regex.Split(Console.ReadLine() ?? string.Empty, "\\s");
var commands = _container.Resolve<IEnumerable<ICommand>>();
var cmd = commands.FirstOrDefault(m => m.Shortcuts.Contains(commandLine.FirstOrDefault()));
if (cmd != null)
{
if (cmd.Execute(commandLine.Skip(1).ToArray()))
break;
}
else Console.WriteLine(Resources.InvalidCommand);
}
Task.Factory.StartNew(() => router.Stop()).Wait();
_container.Dispose();
return 0;
}
示例6: Main
//.........这里部分代码省略.........
commerce5.ProcessOrder(orderInfo);
#endregion
break;
case "6":
#region module usage (Commerce6)
builder.RegisterType<Commerce6>();
builder.RegisterModule<ProcessorRegistrationModule>();
Container = builder.Build();
Commerce6 commerce6 = Container.Resolve<Commerce6>();
commerce6.ProcessOrder(orderInfo);
#endregion
break;
case "7":
#region one-to-many (Commerce7)
builder.RegisterType<Commerce7>();
builder.RegisterType<BillingProcessor>().As<IBillingProcessor>();
builder.RegisterType<CustomerProcessor>().As<ICustomerProcessor>();
builder.RegisterType<NotificationProcessor>().As<INotificationProcessor>();
builder.RegisterType<LoggingProcessor>().As<ILoggingProcessor>();
builder.RegisterType<ProcessorLocator>().As<IProcessorLocator>();
builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
.Where(t => t.Name.StartsWith("Plugin"))
.As<IPostOrderPlugin>();
Container = builder.Build();
Commerce7 commerce7 = Container.Resolve<Commerce7>();
commerce7.ProcessOrder(orderInfo);
#endregion
break;
case "8":
#region post-construction resolve & property injection (Commerce8)
builder.RegisterType<Commerce8>().PropertiesAutowired();
builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
.Where(t => t.Name.EndsWith("Processor"))
.As(t => t.GetInterfaces().FirstOrDefault(
i => i.Name == "I" + t.Name));
builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
.Where(t => t.Name.StartsWith("Plugin"))
.As<IPostOrderPlugin>();
builder.RegisterType<ProcessorLocator>().As<IProcessorLocator>();
Container = builder.Build();
//Commerce8 commerce8 = new Commerce8();
Commerce8 commerce8 = Container.Resolve<Commerce8>();
commerce8.ProcessOrder(orderInfo);
#endregion
break;
case "9":
#region constructor finder (Commerce9)
builder.RegisterType<Commerce9>().WithParameters(new List<Autofac.Core.Parameter>() {
new NamedParameter("a", 1),
new NamedParameter("b", 1),
new NamedParameter("c", 1),
new NamedParameter("d", 1) });
#region fix
//builder.RegisterType<Commerce9>().WithParameters(new List<Autofac.Core.Parameter>() {
// new NamedParameter("a", 1),
// new NamedParameter("b", 1),
// new NamedParameter("c", 1),
// new NamedParameter("d", 1) }).FindConstructorsWith(new AwesomeConstructorFinder());
#endregion
builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
.Where(t => t.Name.EndsWith("Processor"))
.As(t => t.GetInterfaces().FirstOrDefault(
i => i.Name == "I" + t.Name));
builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
.Where(t => t.Name.StartsWith("Plugin"))
.As<IPostOrderPlugin>();
builder.RegisterType<ProcessorLocator>().As<IProcessorLocator>();
Container = builder.Build();
Commerce9 commerce9 = Container.Resolve<Commerce9>();
commerce9.ProcessOrder(orderInfo);
#endregion
break;
}
Container.Dispose();
Console.WriteLine();
Console.WriteLine("Press 'Enter' for menu.");
Console.ReadLine();
Console.Clear();
}
}
}
示例7: ShutdownServices
protected virtual async Task ShutdownServices(IContainer container)
{
Log.Info(m => m("Received OnAppDisposing event from OWIN container."));
var taskRunner = container.Resolve<ITaskRunner>();
var pendingTasks = taskRunner.PendingTasks;
if (pendingTasks.Length > 0)
{
Log.Info(m => m("Waiting for {0} background tasks.", pendingTasks.Length));
await Task.WhenAll(pendingTasks);
}
Log.Info(m => m("Disposing Autofac application container."));
container.Dispose();
}
示例8: CloseApplication
private static void CloseApplication(IContainer container)
{
var context = container.Resolve<ApplicationContext>();
container.Dispose();
context.ExitThread();
}
示例9: Main
public static int Main(string[] args)
{
_container = CreateContainer ();
var builder = new ContainerBuilder();
builder.RegisterInstance(_container)
.ExternallyOwned();
builder.Update(_container);
var networkSettings = _container.Resolve <NetworkSettings> ();
networkSettings.TTL = 5;
var router = _container.Resolve<INetworkMessageRouter> ();
router.Subscribe<HelloMessage>()
.OnSuccess((ep, m) =>
{
Console.WriteLine("Get message {0} from {1}:{2}", m, ep.Address, ep.Port);
m.Sender.IpAddress = ep.Address;
_container.Resolve<UsersService>().Add(m.Sender);
router.PublishFor(new []{m.Sender.Id}, new EchoMessage(_container.Resolve<ISession>().CurrentUser)).First().Run();
});
router.Subscribe<EchoMessage>()
.OnSuccess((ep, m) =>
{
Console.WriteLine("Get message {0} from {1}:{2}", m, ep.Address, ep.Port);
m.Sender.IpAddress = ep.Address;
_container.Resolve<UsersService>().Add(m.Sender);
});
router.Subscribe<TextMessage>()
.OnSuccess((rp, m) =>
{
var user = _container.Resolve<UsersService>().Get(rp);
Console.WriteLine("{0}:{1}", user != null ? user.Title: Properties.Resources.UnknowUser, m.Text);
});
router.Subscribe<AddCloudTrackMessage> ()
.OnSuccess((rp, m) =>
{
Console.WriteLine ("Cloud track request " + m.Track.Source);
_container.Resolve<IMusicPlayer> ().QueueTrack (m.Sender, m.Track);
});
Task.Factory.StartNew(async () => await router.StartAsync());
Console.CancelKeyPress += ConsoleOnCancelKeyPress;
_runing = true;
var users = _container.Resolve<UsersService> ();
var player = _container.Resolve<IMusicPlayer> ();
while (true) {
router.PublishFor (users.GetUserIds (),
new HubMessagePlaylistWasUpdated () {
User = _container.Resolve<ISession> ().CurrentUser,
PlayingTrack = player.CurrentPlayedEntry,
Playlist = player.Playlist
});
Thread.Sleep (100);
}
while (_runing)
{
Console.Write("hubl>: ");
var commandLine = Regex.Split(Console.ReadLine() ?? string.Empty, "\\s");
var commands = _container.Resolve<IEnumerable<ICommand>>();
var cmd = commands.FirstOrDefault(m => m.Shortcuts.Contains(commandLine.FirstOrDefault()));
if (cmd != null)
{
if (cmd.Execute(commandLine.Skip(1).ToArray()))
break;
}
else Console.WriteLine(Properties.Resources.InvalidCommand);
}
Task.Factory.StartNew(() => router.StopAsync()).Wait();
_container.Dispose();
return 0;
}
示例10: RootSubscriptions
private IEnumerable<IDisposable> RootSubscriptions(IContainer container)
{
yield return _configServiceLocator.OnRegisted(
Observer.Create<IList<ComponentRegistrationValue>>(buffer => _eventAggregator.Publish(new RxAppServiceLocatorChangingEvent(buffer))));
yield return _eventAggregator.GetEvent<OpenNewLifetimeScopeCommand>().Subscribe(command =>
{
_configServiceLocator.Upate(container.BeginLifetimeScope(command.Action));
_logger.Info(string.Format("RxApp ServiceLocator setup success on thread {0}.", Thread.CurrentThread));
});
yield return _eventAggregator.GetEvent<RxAppServiceLocatorChangingEvent>().Subscribe(e =>
{
e.Update(container);
_logger.Info(string.Format("RxApp ServiceLocator Registrations updated on thread {0}.", Thread.CurrentThread));
});
yield return Disposable.Create(() =>
{
container.Dispose();
_logger.Info("Startup root container disposed");
});
}