static void Main(string[] args) { var builder = new ContainerBuilder(); builder.RegisterType <TwitterService>().As <ITwitterService>(); builder.RegisterType <TwitterRepository>().As <ITwitterRepository>(); builder.RegisterType <TextFile>().As <ITextFIle>(); builder.RegisterType <DalUsers>().As <IDalUsers>(); builder.RegisterType <DalTweets>().As <IDalTweets>(); builder.RegisterType <Report>().As <IReport>(); builder.RegisterType <Writer>().As <IWriter>(); builder.RegisterType <TweetProcess>().As <ITweetProcess>(); Container = builder.Build(); using (var scope = Container.BeginLifetimeScope()) { try { var twitterService = scope.Resolve <ITwitterService>(); twitterService.PrintReport(); } catch (Exception e) { Logger.Error(e); } } }
protected void Initialize() { ContainerBuilder = new ContainerBuilder(); ContainerBuilder.RegisterType <INGTransferHandle>().As <TransferHandle>(); ContainerBuilder.RegisterType <TransferMoney>().As <TransferMoney>(); ContainerBuilder.RegisterType <IngLogTransfer>().As <ILogTransfers>(); //builder.RegisterType<OnlineState>().Keyed<IDeviceState>(DeviceState.Online); //builder.RegisterType<OfflineState>().Keyed<IDeviceState>(DeviceState.Offline); Autofac.IContainer container = ContainerBuilder.Build(); Scope = container.BeginLifetimeScope(); }