/// <summary> /// 应用程序的主入口点。 /// </summary> static void Main(string[] args) { Config.Current.IgnoreAssemblies(IgnoreAssemblyFiles).With(); IIocBuilder builder = new AutofacBuilder(); IocInstance.RegisterBuilder(builder); IocInstance.AutoRegister(Config.Current.TypesToScan); builder.RegisterModule(new JsonNetModule()); builder.RegisterType <IChangeVersionManager, JsonChangeVersionManager>(LifeTimeScope.Singleton); builder.RegisterType <IObjectProvider <IEnumerable <VersionInfo> >, JsonFileObjectProvider <IEnumerable <VersionInfo> > >(LifeTimeScope.Singleton, getConstructorParameters: (ctx) => { Dictionary <string, object> paras = new Dictionary <string, object>(); paras.Add("jsonFile", Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "versions.js")); paras.Add("jsonSerializer", ctx.Resolve <IJsonSerializer>()); return(paras); }); builder.RegisterConfig(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ioc.config")); IocInstance.Build(); IocInstance.Start(); if (args.Length > 0) { if (args.Any(o => o.ToLower() == "-monitor")) { if (args.Any(o => o.ToLower() == "-service")) { ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new MonitorService() }; ServiceBase.Run(ServicesToRun); } else { Monitors.Start(); Console.WriteLine(":: Monitoring ::"); Console.ReadLine(); Monitors.Stop(); Console.WriteLine("Stopping....."); } } else if (args.Any(o => o.ToLower() == "-init")) { Console.WriteLine(":: Initializing ::"); IBatchIndexWriter biw = IocInstance.Container.Resolve <IBatchIndexWriter>(); biw.Run(); Console.WriteLine(":: Initialized ::"); Console.ReadLine(); Console.WriteLine("Stopping....."); } } }
/// <summary> /// 应用程序的主入口点。 /// </summary> static void Main(string[] args) { Config.Current.IgnoreAssemblies(IgnoreAssemblyFiles).With(); IIocBuilder builder = new AutofacBuilder(); IocInstance.RegisterBuilder(builder); IocInstance.AutoRegister(Config.Current.TypesToScan); builder.RegisterModule(new JsonNetModule()); builder.RegisterType<IChangeVersionManager, JsonChangeVersionManager>(LifeTimeScope.Singleton); builder.RegisterType<IObjectProvider<IEnumerable<VersionInfo>>, JsonFileObjectProvider<IEnumerable<VersionInfo>>>(LifeTimeScope.Singleton, getConstructorParameters: (ctx) => { Dictionary<string, object> paras = new Dictionary<string, object>(); paras.Add("jsonFile", Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "versions.js")); paras.Add("jsonSerializer", ctx.Resolve<IJsonSerializer>()); return paras; }); builder.RegisterConfig(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ioc.config")); IocInstance.Build(); IocInstance.Start(); if (args.Length > 0) { if (args.Any(o => o.ToLower() == "-monitor")) { if (args.Any(o => o.ToLower() == "-service")) { ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new MonitorService() }; ServiceBase.Run(ServicesToRun); } else { Monitors.Start(); Console.WriteLine(":: Monitoring ::"); Console.ReadLine(); Monitors.Stop(); Console.WriteLine("Stopping....."); } } else if (args.Any(o => o.ToLower() == "-init")) { Console.WriteLine(":: Initializing ::"); IBatchIndexWriter biw = IocInstance.Container.Resolve<IBatchIndexWriter>(); biw.Run(); Console.WriteLine(":: Initialized ::"); Console.ReadLine(); Console.WriteLine("Stopping....."); } } }
public override IRuntimeTypeRegistrarModifier <object> RegisterNamed(string name) { var simpleBuilder = (IRuntimeTypeRegistrar <object>) this; var autofacRegistrar = AutofacBuilder.RegisterType(ImplementationType).Named <object>(name); return(new AutofacRuntimeTypeRegistrarModifier <object>(simpleBuilder, autofacRegistrar)); }
public virtual IRuntimeTypeRegistrarModifier <TContract> Register() { var simpleBuilder = (IRuntimeTypeRegistrar <TContract>) this; var autofacRegistrar = AutofacBuilder.RegisterType(ImplementationType).As <TContract>(); return(new AutofacRuntimeTypeRegistrarModifier <TContract>(simpleBuilder, autofacRegistrar)); }
private void register(IReadOnlyCollection <Type> serviceTypes, Type concreteType, LifeStyle lifeStyle, string key = null) { if (concreteType.IsGenericTypeDefinition) { return; } var builder = AutofacBuilder .RegisterType(concreteType) .As(serviceTypes.ToArray()) .ExternallyOwned(); if (!string.IsNullOrEmpty(key)) { builder.Keyed(key, concreteType); } if (lifeStyle == LifeStyle.Singleton) { builder.SingleInstance(); } if (_hasActivationHooks) { _activationHooks.Each(x => builder.OnActivated(x.OnActivated)); } }