static void Main(string[] args) { var factory = new Factory("MyApp", new MyLogger()); // Register the type. factory.Type<IMyType>(typeof(MyType)); // Create an instance and pass in constructor arguments. var myFactoryCreatedObject = factory.CreateInterface<IMyType>("Hello", "Factory"); Console.WriteLine(myFactoryCreatedObject.Message); }
static void Main(string[] args) { var factory = new Factory("MyApp", new MyLogger()); // Auto register types. factory.AutoRegisterTypes(); // Create an instance. var myFactoryCreatedObject = factory.CreateInterface<IMyType>(); Console.WriteLine(myFactoryCreatedObject.Message); }
static void Main(string[] args) { var factory = new Factory("MyApp", new MyLogger()); // Register a dependency. factory.Dep<IMyDependency>(new MyDependency()); // Register the type. factory.Type<IMyType>(typeof(MyType)); // Create an instance with dependency injected. var myFactoryCreatedObject = factory.CreateInterface<IMyType>(); Console.WriteLine(myFactoryCreatedObject.Message); }
static void Main(string[] args) { var logger = new MyLogger(); var factory = new Factory("MyApp", logger, new Reflection()); // Auto register types. factory.AutoRegisterTypes(); // Auto bootstrap singletons for classes marked as [Singleton]. factory.AutoInstantiateSingletons(); // Create an instance. var myFactoryCreatedObject = factory.CreateInterface<IMyType>(); Console.WriteLine(myFactoryCreatedObject.Message); }
static void Main(string[] args) { var logger = new MyLogger(); var factory = new Factory("MyApp", logger); // Auto register types. factory.AutoRegisterTypes(); // Normal singleton bootstrapping... although the lazy singleton isn't instantiated yet. factory.AutoInstantiateSingletons(); // Create an instance. // This will instantiate the lazy singleton at the point when it is requested by the dependency injection system. var myFactoryCreatedObject = factory.CreateInterface<IMyType>(); Console.WriteLine(myFactoryCreatedObject.Message); }
static void Main(string[] args) { var logger = new MyLogger(); var factory = new Factory("MyApp", logger); // Auto register types. factory.AutoRegisterTypes(); // Auto bootstrap singletons for classes marked as [Singleton]. var singletonManager = factory.AutoInstantiateSingletons(); // Start-up startable singletons. singletonManager.Startup(); // Create an instance. var myFactoryCreatedObject = factory.CreateInterface<IMyType>(); Console.WriteLine(myFactoryCreatedObject.Message); // Shutdown startable singletons. singletonManager.Shutdown(); }