Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Autofac;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace DependencyInjection {
- class Program {
- static void Main(string[] args) {
- List<int> speakerList = new List<int>();
- List<float> presentationList = new List<float>();
- using (var container = ContainerListi.SpeakerListContainer()) {
- var speakerController = container.Resolve<IGetSpeakerList>();
- speakerList = speakerController.GetListu();
- }
- using (var container = ContainerListi.PresentationListContainer()) {
- var presentationController = container.Resolve<IGetPresentationList>();
- presentationList = presentationController.GetListu();
- }
- for (int i = 0; i < speakerList.Count; i++)
- Console.WriteLine(speakerList[i]);
- for (int i = 0; i < presentationList.Count; i++)
- Console.WriteLine(presentationList[i]);
- Console.WriteLine("Negativni brojevi [ -1 -2 -3 ] su dummy PREDAVACI\n" +
- "Negativni brojevi [ -10 -20 -30 ] su dummy PREDAVANJA\n" +
- "Pozitivni brojeve [ 1 2 3 ] su real PREDAVACI\n" +
- "Pozitivni brojevi [ 10 20 30 ] su real PREDAVANJA");
- }
- }
- // Predavač dummy
- class DummySpeakerController : IGetSpeakerList {
- public List<int> GetListu() {
- return new List<int>() { -1, -2, -3 };
- }
- }
- // Predavač real
- class CloudSpeakerController : IGetSpeakerList {
- public List<int> GetListu() {
- return new List<int>() { 1, 2, 3 };
- }
- }
- // Predavanja dummy
- class DummyPresentationController : IGetPresentationList {
- public List<float> GetListu() {
- return new List<float>() { -10, -20, -30 };
- }
- }
- // Predavanja real
- class CloudPresentationController : IGetPresentationList {
- public List<float> GetListu() {
- return new List<float>() { 10, 20, 30 };
- }
- }
- class ContainerListi {
- public static IContainer SpeakerListContainer() {
- var builder = new ContainerBuilder();
- builder.RegisterType<DummySpeakerController>().As<IGetSpeakerList>();
- return builder.Build();
- }
- public static IContainer PresentationListContainer() {
- var builder = new ContainerBuilder();
- builder.RegisterType<CloudPresentationController>().As<IGetPresentationList>();
- return builder.Build();
- }
- }
- // Interface za predavace - int = Speaker
- public interface IGetSpeakerList {
- List<int> GetListu();
- }
- // Interface za predavanja - float = Presentation
- public interface IGetPresentationList {
- List<float> GetListu();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement