// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var queuePublisher = new QueueClient(publisherConnectionString, Queues.GeneralCommand); services.AddTransient <IQueueMessengerClient>(sp => new MessengerClient(queuePublisher)); var queueListener = new QueueClient(subscriberConnectionString, Queues.GeneralCommand); services.AddTransient <IQueueObserverClient>(sp => new ObserverClient(queueListener)); var topicBus = new TopicClient(publisherConnectionString, Topics.GeneralInfo); services.AddTransient <ITopicMessengerClient>(sp => new MessengerClient(topicBus)); var subscriberBus = new SubscriptionClient(subscriberConnectionString, Topics.GeneralInfo, "gis"); services.AddSingleton <ITopicObserverClient>((sp) => { var observer = new ObserverClient(subscriberBus, false); observer.RegisterForLogNotifications(LogProcessor); return(observer); }); // START the Logger, connects to Kibana // logger = new LogManager(Configuration["ElasticConfiguration:Uri"]); logger.Log(new LogEntry { Id = 1, Title = "Administration Management App initializing.", Type = LogType.Information.ToString() }); services.AddSingleton <Universal.Contracts.Logging.ILogger>(logger); // ADD a default data storage mechanism // services.AddDbContext <ApplicationDbContext>(options => options.UseInMemoryDatabase("Messages")); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); var container = services.BuildServiceProvider(); var repository = new MessageRepository( container.GetService <ApplicationDbContext>()); services.AddSingleton <MessageRepository>(repository); services.AddSingleton <MessagingService>(); services.AddSingleton <IFileRepository>(fr => { return(new AzureFileRepository( new AzureFileReader( Configuration["UploadStorageAcctName"], Configuration["StorageAccountKey"], "gis-uploads"))); }); services.AddSingleton <FileService>(); services.AddSingleton <MessageHub>(); services.AddSignalR(); }
static void Main(string[] args) { bool exitLoop = false; while (!exitLoop) { Console.WriteLine(); Console.WriteLine("Please type the number of type of design patterns to veiw"); Console.WriteLine("0 - Exit"); Console.WriteLine("1 - Creational"); Console.WriteLine("2 - Structural"); Console.WriteLine("3 - Behaivoral"); ConsoleKeyInfo keyInfo = Console.ReadKey(); Console.WriteLine(); switch (keyInfo.KeyChar.ToString()) { case "0": exitLoop = true; break; case "1": while (!exitLoop) { Console.WriteLine("Please select Creational Pattern to demo:"); Console.WriteLine("0 - Exit"); Console.WriteLine("1 - Simple Factory"); Console.WriteLine("2 - Factory Method"); Console.WriteLine("3 - Abstract Factory"); Console.WriteLine("4 - Builder"); Console.WriteLine("5 - Fluent Interface"); Console.WriteLine("6 - Prototype"); Console.WriteLine("7 - Singleton"); keyInfo = Console.ReadKey(); Console.WriteLine(); switch (keyInfo.KeyChar.ToString()) { case "0": exitLoop = true; break; case "1": SimpleFactoryClient simpleFactoryClient = new SimpleFactoryClient(); simpleFactoryClient.PrintSimpleFactory(); break; case "2": FactoryMethodClient factoryMethodClient = new FactoryMethodClient(); factoryMethodClient.PrintFactoryMethod(); break; case "3": AbstractFactoryClient abstractFactoryClient = new AbstractFactoryClient(); abstractFactoryClient.PrintAbstractFactory(); break; case "4": BuilderClient builderClient = new BuilderClient(); builderClient.PrintBuilder(); break; case "5": FluentInterfaceClient fluentInterfaceClient = new FluentInterfaceClient(); fluentInterfaceClient.PrintFluentInterface(); break; case "6": PrototypeClient prototypeClient = new PrototypeClient(); prototypeClient.PrintPrototype(); break; case "7": SingletonClient singletonClient = new SingletonClient(); singletonClient.PrintSingleton(); break; default: Console.WriteLine("Selection must be 0-7"); break; } } exitLoop = false; break; case "2": while (!exitLoop) { Console.WriteLine("Please select Structural Pattern to demo:"); Console.WriteLine("0 - Exit"); Console.WriteLine("1 - Adapter"); Console.WriteLine("2 - Facade"); Console.WriteLine("3 - Decorator"); Console.WriteLine("4 - Bridge"); Console.WriteLine("5 - Composite"); Console.WriteLine("6 - Proxy"); Console.WriteLine("7 - Flyweight"); keyInfo = Console.ReadKey(); Console.WriteLine(); switch (keyInfo.KeyChar.ToString()) { case "0": exitLoop = true; break; case "1": AdapterClient adapterClient = new AdapterClient(); adapterClient.PrintAdapter(); break; case "2": FacadeClient facadeClient = new FacadeClient(); facadeClient.PrintFacade(); break; case "3": DecoratorClient decoratorClient = new DecoratorClient(); decoratorClient.PrintDecorator(); break; case "4": BridgeClient bridgeClient = new BridgeClient(); bridgeClient.PrintBridge(); break; case "5": CompositeClient compositeClient = new CompositeClient(); compositeClient.PrintComposite(); break; case "6": ProxyClient proxyClient = new ProxyClient(); proxyClient.PrintProxy(); break; case "7": FlyweightClient flyweightClient = new FlyweightClient(); flyweightClient.PrintFlyweight(); break; default: Console.WriteLine("Selection must be 0-7"); break; } } exitLoop = false; break; case "3": while (!exitLoop) { Console.WriteLine("Please select Behaivoral Pattern to demo:"); Console.WriteLine("0 - Exit"); Console.WriteLine("1 - Iterator"); Console.WriteLine("2 - Observer"); Console.WriteLine("3 - Chain Of Responsibility"); Console.WriteLine("4 - State"); Console.WriteLine("5 - Template"); Console.WriteLine("6 - Command"); Console.WriteLine("7 - Visitor"); Console.WriteLine("8 - Strategy"); Console.WriteLine("9 - Interpreter"); Console.WriteLine("10 - Mediator"); Console.WriteLine("11 - Memento"); string entered = Console.ReadLine(); Console.WriteLine(); switch (entered) { case "0": exitLoop = true; break; case "1": IteratorClient iteratorClient = new IteratorClient(); iteratorClient.PrintIterator(); break; case "2": ObserverClient observerClient = new ObserverClient(); observerClient.PrintObserver(); break; case "3": ChainOfResponsibilityClient chainOfResponsibilityClient = new ChainOfResponsibilityClient(); chainOfResponsibilityClient.PrintChainOfResponsibility(); break; case "4": StateClient stateClient = new StateClient(); stateClient.PrintState(); break; case "5": TemplateClient templateClient = new TemplateClient(); templateClient.PrintTemplate(); break; case "6": CommandClient commandClient = new CommandClient(); commandClient.PrintCommand(); break; case "7": VisitorClient visitorClient = new VisitorClient(); visitorClient.PrintVisitor(); break; case "8": StrategyClient strategyClient = new StrategyClient(); strategyClient.PrintStrategy(); break; case "9": InterpreterClient interpreterClient = new InterpreterClient(); interpreterClient.PrintInterpreter(); break; case "10": MediatorClient mediatorClient = new MediatorClient(); mediatorClient.PrintMediator(); break; case "11": MementoClient mementoClient = new MementoClient(); mementoClient.PrintMemento(); break; default: Console.WriteLine("Selection must be 0-11"); break; } } exitLoop = false; break; default: Console.WriteLine("Must enter number 0 -3"); break; } } Console.WriteLine("End of Design Patterns examples"); Console.WriteLine("Type any key to exit"); Console.ReadKey(); }
static void Main(string[] args) { //FactoryMethod var shipFactory = new ShipFactory(); var fabricMethodClient = new FabricMethodClient(shipFactory); fabricMethodClient.Deliver(); var cargoFactory = new CargoFactory(); fabricMethodClient.SetTransportFactory(cargoFactory); fabricMethodClient.Deliver(); //AbstractFactory var humanFactory = new HumanUnitFactory(); var abstractFactoryClient = new AbstractFactoryClient(humanFactory); abstractFactoryClient.DoSquad(); var orkFactory = new OrkUnitFactory(); abstractFactoryClient.SetUnitFactory(orkFactory); abstractFactoryClient.DoSquad(); //Builder var opossumBuilder = new OpossumBuilder(); var director = new Director(opossumBuilder); var sectionalUnit = director.GetUnit(); sectionalUnit.DoStuff(); var baldBuilder = new BaldBuilder(); director.SetBuilder(baldBuilder); sectionalUnit = director.GetUnit(); sectionalUnit.DoStuff(); //Prototype var prototype = new PrototypeSample(2); prototype.SetProperty(1.0f); prototype.DoStuff(); var clone = (PrototypeSample)prototype.Clone(); clone.DoStuff(); //Singleton Singleton.Instance.SingletonScream(); //Adapter var adapterClient = new AdapterClient(); adapterClient.DoStuff(); //Bridge var bridgeClient = new BridgeClient(); bridgeClient.DoStuff(); //Composite var compositeClient = new CompositeClient(); compositeClient.DoStuff(); //Decorator var decoratorClient = new DecoratorClient(); decoratorClient.DoStuff(); //Facade var facadeClient = new Facade(); facadeClient.DoStuff(); //Flyweight var flyweightClient = new FlyweightClient(); flyweightClient.DoStuff(); //Proxy var proxyClient = new ProxyClient(); proxyClient.DoStuff(); //CoR var corClient = new CoRClient(); corClient.DoStuff(); //Command var commandClient = new CommandClient(); commandClient.DoStuff(); //Iterator var iteratorClient = new IteratorClient(); iteratorClient.DoStuff(); //Mediator var mediatorClient = new MediatorClient(); mediatorClient.DoStuff(); //Memento var mementoClient = new MementoClient(); mementoClient.DoStuff(); //Observer var observerClient = new ObserverClient(); observerClient.DoStuff(); //Strategy var strategyClient = new StrategyClient(); strategyClient.DoStuff(); //TemplateMethod var templateMethodClient = new TemplateMethodClient(); templateMethodClient.DoStuff(); //Visitor var visitorClient = new VisitorClient(); visitorClient.DoStuff(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { logger = new LogManager(Configuration["ElasticConfiguration:Uri"]); logger.Log(new LogEntry { Id = 1, Title = "Administration Management App initializing.", Type = LogType.Information.ToString() }); services.AddSingleton <Universal.Contracts.Logging.ILogger>(logger); var serviceBus = new QueueClient(ServiceBusConnectionString, Queues.GeneralCommand); services.AddTransient <IQueueMessengerClient>(sp => new MessengerClient(serviceBus)); var qObserver = new QueueClient(subscriberConnectionString, Queues.GeneralCommand); services.AddTransient <IQueueObserverClient>(sp => { var observer = new ObserverClient(qObserver); observer.RegisterForLogNotifications(LogProcessor); return(observer); }); var topicBus = new TopicClient(ServiceBusConnectionString, Topics.GeneralInfo); services.AddTransient <ITopicMessengerClient>(sp => new MessengerClient(topicBus)); var subscriberBus = new SubscriptionClient(ServiceBusConnectionString, Topics.GeneralInfo, "gis"); services.AddSingleton <ITopicObserverClient>(sp => { var observer = new ObserverClient(subscriberBus, false); observer.RegisterForLogNotifications(LogProcessor); return(observer); }); services.AddSingleton <LayerTileCacheAccessor>(new LayerTileCacheAccessor( () => new SimpleTileCacheStorage <ITransformedTile>(), () => new SimpleTileCacheStorage <ITile>())); services.AddSingleton <ProcessingService>(); services.AddSingleton <MessageRepository>(new MessageRepository()); var fileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/layers")); var serverIp = Configuration["ServerAddress:Https"]; services.AddSingleton <ILayerInitializationService>(new LayerInitializationFileService(fileProvider, serverIp)); services.AddTransient <Generator>(); services.AddTransient <TileRetrieverService>(); services.AddSingleton <IFileProvider>(fileProvider); services.AddSingleton <IFileRepository>(fr => { return(new AzureFileRepository( new AzureFileReader( Configuration["AzureFileStorage:UploadStorageAcctName"], Configuration["AzureFileStorage:StorageAccountKey"], Configuration["AzureFileStorage:FileStoreName"]))); }); services.AddSingleton <ITileCacheStorage <ITile> >(new SimpleTileCacheStorage <ITile>()); services.AddSingleton <ITileCacheStorage <ITransformedTile> >(new SimpleTileCacheStorage <ITransformedTile>()); services.AddTransient <ITileContext>((sp) => { return(new SimpleTileContext() { MaxZoom = 14, Buffer = 64, Extent = 4096, Tolerance = 3 }); }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); // Adding Cross Origin Request requires the AddCors() call in the ConfigureServices, from this: // // https://docs.microsoft.com/en-us/aspnet/core/security/cors?view=aspnetcore-2.2 services.AddCors(options => { options.AddDefaultPolicy( builder => { builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader(); }); }); // Build the container to allow for the registration of message receivers // var container = services.BuildServiceProvider(); var processing = container.GetService <ProcessingService>(); processing.RegisterNotificationHandlers(container.GetService <MessageRepository>(), container.GetService <IFileRepository>()); }