1.引入ABP
2.添加自定义module,继承AbpModule
public class MyAbpModule : AbpModule { public override void Initialize() { IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly()); } } }
3,添加自己的service,继承ITransientDependency
//[Dependency(ServiceLifetime.Transient)] public class Service : ITransientDependency { public void Run() { Console.WriteLine("你好"); } }
4.具体实现
static void Main(string[] args) { using (var bootstrapper = AbpBootstrapper.Create<MyAbpModule>()) { bootstrapper.Initialize(); var service = IocManager.Instance.Resolve<Service>(); service.Run(); Console.ReadKey(); } }
相关分析,
01 AbpBootstrapper: