public IContainer Setup(FreeconServerEnvironment environment, Action <ContainerBuilder> configCallback = null) { var builder = new ContainerBuilder(); // This works sometimes. Other times, you have to do something like: // var neverUsed = typeof(someTypeInAnAssembly); // In order for the CLR to load your assembly up. var assemblies = new List <Assembly>() { typeof(ClientCommRouter).Assembly, typeof(IClientCommRouter).Assembly }; assemblies.AddRange(AppDomain.CurrentDomain.GetAssemblies()); var assemblyArray = assemblies.ToArray(); builder.RegisterAssemblyTypes(assemblyArray) .Where(p => p.Name.EndsWith("Manager") || p.Name.EndsWith("Service") || p.Name.EndsWith("Router")) .AsSelf() .SingleInstance(); builder.RegisterAssemblyTypes(assemblyArray) .Where(p => p.Name.EndsWith("Manager") || p.Name.EndsWith("Service") || p.Name.EndsWith("Router")) .AsImplementedInterfaces() .SingleInstance(); var messageSerializer = new ProtobufMessageSerializer(); var conf = new DevelopNetworkConfig(); var logger = new VerboseLoggerUtil(); // #Yolo exception logging var router = new ReactiveRouter((ex) => logger.Log("Exception: " + ex.ToString(), LogLevel.Error)); // Todo: Command line arguments or something to specify environment. var configManager = new ConfigManager(environment); var networkManager = new NetworkManager(messageSerializer, configManager, logger); // Register dependencies that need configuration. builder.RegisterInstance <ILoggerUtil>(logger).SingleInstance(); builder.RegisterInstance <IMessageSerializer>(messageSerializer); builder.RegisterInstance <ConfigManager>(configManager).SingleInstance(); builder.RegisterInstance <NetworkManager>(networkManager).SingleInstance(); builder.RegisterInstance <IReactiveRouter>(router).SingleInstance(); if (configCallback != null) { configCallback(builder); } Container = builder.Build(); RegisterMappings(Container.Resolve <IClientRequestRouter>()); return(Container); }
public ConfigManager(FreeconServerEnvironment environment) { NetworkConfigs = new List <INetworkConfig>(); switch (environment) { case FreeconServerEnvironment.Development: case FreeconServerEnvironment.Production: NetworkConfigs.Add(new DevelopNetworkConfig()); break; case FreeconServerEnvironment.Test: NetworkConfigs.Add(new TestNetworkConfig()); break; default: throw new Exception("Wrong environment mother f****r"); } }