public IMyShareOptions InitKernel() { TypeDict = TypeMap(MyShareConfig.Assemblies); ServicesCollection.AddMemoryCache(); //添加CQRS服务 ServicesCollection.AddSingleton(new InProcessBus()); ServicesCollection.AddSingleton <ICommandSender>(y => y.GetService <InProcessBus>()); ServicesCollection.AddSingleton <IEventPublisher>(y => y.GetService <InProcessBus>()); ServicesCollection.AddSingleton <IHandlerRegistrar>(y => y.GetService <InProcessBus>()); ServicesCollection.AddSingleton <ISerializer, Serializer>(); ServicesCollection.AddSingleton(new DataContext(_options, TypeDict.Values.ToList())); ServicesCollection.AddScoped <ICache, MemoryCache>(); ServicesCollection.AddSingleton <IEventStore, SampleEventStore>(); ServicesCollection.AddScoped <IRepository, Repository>(); ServicesCollection.AddScoped <ICacheRepository, CacheRepository>(); ServicesCollection.AddScoped <ISession, Session>(); //ServicesCollection.AddScoped<IRepository>(y => new CacheRepository(new Repository(y.GetService(typeof(IEventStore)) as IEventStore), // y.GetService(typeof(IEventStore)) as IEventStore, y.GetService<ICache>())); RegHandlerType(); return(this); }