conditional-binding

Conditional dependency injection binding only when property not null

那年仲夏 提交于 2019-11-29 11:56:43
It is a desktop application which is obliged to impersonate the current user when accessing the underlying data source. How can I tell Ninject not to bind the dependency until the property of a parent object is not null? Application forces user authentication upon startup Once authenticated, a reference to the current user credentials is kept within the IMembershipService Accessing the underlying datasource obliges to have a user authenticated so that the commection string states the credentials to impersonate I am actually using NHibernate, and I need to dynamically create the connection

Bound value in a conditional binding must be of Optional Type

末鹿安然 提交于 2019-11-29 02:15:36
问题 I have a protocol defined: protocol Usable { func use() } and a class that conforms to that protocol class Thing: Usable { func use () { println ("you use the thing") } } I would like to programmatically test whether or not the Thing class conforms to the Usable protocol. let thing = Thing() // Check whether or not a class is useable if let usableThing = thing as Usable { // error here usableThing.use() } else { println("can't use that") } But I get the error Bound value in a conditional

Pattern match and conditionally bind in a single Switch statement

纵饮孤独 提交于 2019-11-28 09:13:22
问题 Is there a way to write this if / else if / else ladder as a switch statement? let x: Any = "123" if let s = x as? String { useString(s) } else if let i = x as? Int { useInt(i) } else if let b = x as? Bool { useBool(b) } else { fatalError() } Here's my attempt: switch x { case let s where s is String: useString(s) case let i where i is Int: useInt(i) case let b where b is Bool: useBool(b) default: fatalError() } It successfully chooses the right path, but s / i / b are still of type Any . The

Conditional dependency injection binding only when property not null

巧了我就是萌 提交于 2019-11-28 05:57:53
问题 It is a desktop application which is obliged to impersonate the current user when accessing the underlying data source. How can I tell Ninject not to bind the dependency until the property of a parent object is not null? Application forces user authentication upon startup Once authenticated, a reference to the current user credentials is kept within the IMembershipService Accessing the underlying datasource obliges to have a user authenticated so that the commection string states the