鉴于以下代码,如何在autofac中解析正确的SomeInstance?
public class BaseClass {}
public class SubClass1 : BaseClass {}
public class SubClass2 : BaseClass {}
public interface IGenericInterface<T> where T : BaseClass {}
public class SomeInstance1<T> : IGenericInterface<T> where T : SubClass1
public class SomeInstance2<T> : IGenericInterface<T> where T : SubClass2
Run Code Online (Sandbox Code Playgroud)
我想根据子类的泛型类型选择SomeInstance1或2.
所以例如我有一个子类的集合(SubClass1,2 ....),并在迭代它们时我想选择正确的SomeInstance类.
我喜欢使用ReSharper单元测试运行器,但它不支持在NUnit 2.5中添加的TestCase属性.是否有任何黑客可以绕过这个?
我显然可以使用另一个测试运行器,但我喜欢ReSharper.
我有一个React Native应用程序,我试图在JavaScript中将一个静默的iOS推送通知发送给处理程序.
我看到的行为是调用didReceiveRemoteNotification
函数,AppDelegate
但我的JavaScript中的处理程序不会被调用,除非应用程序在前台或最近才关闭.
我很困惑的事情显然是应用程序被唤醒并didReceiveRemoteNotification
调用它的功能,但随后调用[RCTPushNotificationManager didReceiveRemoteNotification:notification]
似乎没有做任何事情.
此外,如果我在收到通知后打开应用程序,那么我会看到此时调用React Native处理程序.
我的didReceiveRemoteNotification
功能看起来像这样:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification
{
NSLog(@"didReceiveRemoteNotification");
[RCTPushNotificationManager didReceiveRemoteNotification:notification];
}
Run Code Online (Sandbox Code Playgroud)
在我的React Native应用程序的Root组件中,我有:
componentDidMount() {
AppState.addEventListener('change', this.handleAppStateChange);
PushNotificationIOS.addEventListener('notification', (notification) => {
console.log("notification recieved");
})
}
handleAppStateChange(currentAppState) {
console.log(currentAppState);
}
Run Code Online (Sandbox Code Playgroud)
我正在使用AWS SNS发送推送通知,并显示以下消息:
{
"APNS_SANDBOX":"{\"aps\":{\"content-available\":\"1\"}}"
}
Run Code Online (Sandbox Code Playgroud)
这是来自XCode的日志:
2016-04-20 10:38:01.255 [info][tid:com.facebook.React.JavaScript] inactive
2016-04-20 10:38:01.986 [info][tid:com.facebook.React.JavaScript] background
2016-04-20 10:38:17.279 test[4056:1383261] didReceiveRemoteNotification
2016-04-20 10:38:17.284 [info][tid:com.facebook.React.JavaScript] notification recieved
2016-04-20 10:44:56.330 test[4056:1383261] didReceiveRemoteNotification
2016-04-20 10:44:56.332 [info][tid:com.facebook.React.JavaScript] notification recieved
2016-04-20 10:46:07.091 …
Run Code Online (Sandbox Code Playgroud) 我使用的是Angular UI路由器,这在大多数情况下效果很好.但是,我有一种情况,我不知道提前查询字符串参数的名称.
通常使用UI路由器,您可以定义类似这样的路由:
$stateProvider.state('test', {
url: '/test?testQueryStringParam',
templateUrl: 'Test.html',
controller: 'TestController'
});
Run Code Online (Sandbox Code Playgroud)
然后在我的控制器中,我可以使用$ stateParams访问testQueryStringParam.
但是,使用UI路由器,您无法访问路径定义中未指定的任何查询字符串参数.
Angular框架附带的路由器确实允许您这样做.所以我尝试使用我的UI路由器定义的$ location服务.这确实很有效.
当我想添加查询字符串参数时,我使用:
$location.search("paramName", "paramValue");
Run Code Online (Sandbox Code Playgroud)
当我想获取查询字符串值时,我只是使用:
$location.search()
Run Code Online (Sandbox Code Playgroud)
这会更新URL,但不会重新实例化控制器(如$ state.go($ state.current,{},{reload:true})).这似乎不是一个大问题,因为我可以自己重新加载数据.但是,如果您在浏览器中使用后退按钮,它将再次更改URL,但不会重新实例化控制器.
无论如何还有
我可以使用UI路由器来实现这一点吗?
获取使用$ location来实际重新实例化控制器的解决方法.
作为最后的手段,我也尝试指导更新window.location,但这会刷新整个页面,这是不可接受的.
谢谢
在遵循域驱动设计的应用程序中,您可以使用以下类型的概念
通常你会把缓存代码放到一个昂贵的数据库调用?
我已经看到代码库只是缓存在整个地方,很难监控内存使用情况,很难为其他开发人员提供指导.
请理解我知道您应该只在需要时缓存数据,我只是问一般问题.
我有一个带有动画的 React 应用程序,使用 React Pose ( https://popmotion.io/pose/ )。
这工作正常,但是当我为组件编写集成测试时(使用 react-testing-library),测试失败。
我在运行测试时得到的错误是:
Error: Uncaught [TypeError: Cannot read property '1' of null]
at reportException (/app/node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:66:24)
at invokeEventListeners (/app/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:209:9)
at HTMLUnknownElementImpl._dispatch (/app/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:119:9)
at HTMLUnknownElementImpl.dispatchEvent (/app/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:82:17)
at HTMLUnknownElementImpl.dispatchEvent (/app/node_modules/jsdom/lib/jsdom/living/nodes/HTMLElement-impl.js:30:27)
at HTMLUnknownElement.dispatchEvent (/app/node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:157:21)
at Object.invokeGuardedCallbackDev (/app/node_modules/react-dom/cjs/react-dom.development.js:199:16)
at invokeGuardedCallback (/app/node_modules/react-dom/cjs/react-dom.development.js:256:31)
at commitRoot (/app/node_modules/react-dom/cjs/react-dom.development.js:18427:7)
at completeRoot (/app/node_modules/react-dom/cjs/react-dom.development.js:19884:3) TypeError: Cannot read property '1' of null
at Object.x (/app/node_modules/popmotion-pose/lib/index.js:526:64)
at /app/node_modules/popmotion-pose/lib/index.js:593:51
at Array.forEach (<anonymous>)
at convertPositionalUnits (/app/node_modules/popmotion-pose/lib/index.js:592:27)
at transformPose (/app/node_modules/popmotion-pose/lib/index.js:647:20)
at getParentAnimations (/app/node_modules/pose-core/lib/index.js:113:28)
at Object.set (/app/node_modules/pose-core/lib/index.js:167:28)
at /app/node_modules/react-pose/lib/index.js:203:77
at …
Run Code Online (Sandbox Code Playgroud) 我有一个类接口作为构造函数参数.这个接口有两个实现,我想根据变量决定在运行时使用什么实现.
问题是上面的类是深入一个由Autofac解决的对象层次结构,因此我无法传入参数.
像下面这样的Somehing就是我想要实现的目标.
public interface IInterface1 {}
public interface IInterface2 {}
public class Class1 : IInterface2
{
public Class1(IInterface1 interface1)
{
}
}
public class Class2
{
public Class2(IInterface2 interface2)
{
}
}
public class Class3
{
public void GetClass2Instance(string interface1ImplementationToChoose)
{
// want to change which implementation of IInterface1 is resolved based on the interface1ImplementationToChoose variable
var class2 = container.Resolve<Class2>();
}
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
更新:
为了澄清,这是一个现有的对象层次结构,现有的应用程序使用它可以正常工作.此外,对象模型比此示例中显示的大得多.因此,我真的不想将工厂传递给对象图中的每个构造函数,以供该图中深层的类使用.
有没有办法让IInterface1的不同实现传递到Class1而没有Class2知道它的任何内容?
谢谢
我试图使用以下说明在Windows上运行gitflow:https://github.com/nvie/gitflow(我使用的是Windows Server 2003 SP2 64位)
我试过Cygwin和msysgit.
使用Cygwin,调用wget只返回任何内容.
使用msysgit我得到了更多,但当我尝试运行git flow init时,我收到以下错误:
C:\Program Files (x86)\Git/libexec/git-core/git-flow: line 45: dirname: command not found
C:\Program Files (x86)\Git/libexec/git-core/git-flow: line 68: /gitflow-common: No such file or directory
C:\Program Files (x86)\Git/libexec/git-core/git-flow: line 76: /gitflow-shFlags: No such file or directory
Run Code Online (Sandbox Code Playgroud)
查看git-flow bash文件中的第一个错误,第45行包含:
export GITFLOW_DIR=$(dirname "$0")
Run Code Online (Sandbox Code Playgroud)
我也尝试过这里的步骤https://github.com/nvie/gitflow/issues/issue/25?authenticity_token=54d6387519b4751c2fb13840c52bb819dee10af4,但它没有任何区别.
有任何想法吗?
谢谢