public void Test2() { var container = new Container(); var m = new TestFoo(); container.AutoWire(m); Assert.Throws<ResolutionException>(() => container.Resolve<IBar>()); Assert.IsNull(m.Bar); // FAILS HERE }
public void Test1() { var container = new Container(); var m = new TestFoo(); container.Register<IBar>(new Bar()); Assert.NotNull(container.Resolve<IBar>(), "Resolve"); container.AutoWire(m); Assert.NotNull(m.Bar, "Autowire"); }
public override void Configure (Container container) { LogManager.LogFactory = new NLogFactory (); this.RequestFilters.Add ((req, resp, requestDto) => { ILog log = LogManager.GetLogger (GetType ()); log.Info (string.Format ( "REQ {0}: {1} {2} {3} {4} {5}\n", DateTimeOffset.Now.Ticks, req.HttpMethod, req.OperationName, req.RemoteIp, req.RawUrl, req.UserAgent)); }); this.RequestFilters.Add ((req, resp, requestDto) => { ILog log = LogManager.GetLogger (GetType ()); log.Info (string.Format ( "RES {0}: {1} {2}\n", DateTimeOffset.Now.Ticks, resp.StatusCode, resp.ContentType)); }); JsConfig.DateHandler = JsonDateHandler.ISO8601; Plugins.Add (new AuthFeature (() => new AuthUserSession (), new IAuthProvider[] { new BasicAuthProvider () }) ); Plugins.Add (new RegistrationFeature ()); Plugins.Add (new RequestLogsFeature ()); container.RegisterAutoWiredAs<Scheduler, IScheduler> (); container.Register<ICacheClient> (new MemoryCacheClient ()); container.Register<IDbConnectionFactory> (new OrmLiteConnectionFactory (@"Data Source=db.sqlite;Version=3;", SqliteOrmLiteDialectProvider.Instance)); //Use OrmLite DB Connection to persist the UserAuth and AuthProvider info container.Register<IUserAuthRepository> (c => new OrmLiteAuthRepository (c.Resolve<IDbConnectionFactory> ())); Plugins.Add (new ValidationFeature ()); container.RegisterValidators (typeof(AppHost).Assembly); var config = new EndpointHostConfig (); if (m_debugEnabled) { config.DebugMode = true; //Show StackTraces in service responses during development config.WriteErrorsToResponse = true; config.ReturnsInnerException = true; } container.AutoWire (this); SetConfig (config); CreateMissingTables (container); }
public void Can_AutoWire_Existing_Instance() { var test = new Test(); var container = new Container(); container.Register<IFoo>(c => new Foo()); container.Register<IBar>(c => new Bar()); container.Register<int>(c => 10); container.AutoWire(test); Assert.That(test.Foo, Is.Not.Null); Assert.That(test.Bar, Is.Not.Null); Assert.That(test.Foo2 as Foo, Is.Null); Assert.That(test.Names, Is.Not.Null); Assert.That(test.Age, Is.EqualTo(0)); }