c#unity容器构造函数注入与运行时值

时间:2016-06-11 14:05:36

标签: c# unity-container

我在我的应用程序中使用基于统一容器XML配置的构造函数注入。我需要将一些运行时值传递给构造函数。因为我使用的是XML配置,所以有没有办法在代码中执行此操作?

e.g。

public void OROPeration()
       {
           IplImage orImage = Cv.CreateImage(src.Size, BitDepth.U8, 3);
           Cv.Or(src, mask, orImage, null);
           Cv.SaveImage("4.jpg", orImage);
       }

谢谢!提前。

1 个答案:

答案 0 :(得分:0)

trackerService = ServiceGateway.createService(TrackerService.class); Call<Profile> call = trackerService.updateProfile(getString(R.string.app_type), "Bearer " + userPrefs.accessToken().get(), new Profile(trimedInvitationMessage, title, String.valueOf(selectedCountry.getCountryCode()), mobilePhone, countryISO, fullName)); call.enqueue(new Callback<Profile>() { @Override public void onResponse(Call<Profile> call, Response<Profile> response) { if (response.body() != null) { } else { if (response.raw().code() == 401) { Call<TokenResponse> refreshTokenCall = trackerService.refreshToken(userPrefs.clientId().get(), userPrefs.clientSecret().get(), "refresh_token", userPrefs.refreshToken().get()); refreshTokenCall.enqueue(new Callback<TokenResponse>() { @Override public void onResponse(Call<TokenResponse> call, Response<TokenResponse> response) { if (response.body() != null) { updateAdviserProfile(trimedInvitationMessage, title, mobilePhone, countryISO, fullName); } else { userPrefs.clear(); Intent intent = new Intent(WelcomeActivity_.launcher(EditProfileActivity.this)); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); startActivity(WelcomeActivity_.launcher(EditProfileActivity.this)); } } @Override public void onFailure(Call<TokenResponse> call, Throwable t) { } }); } else if (response.raw().code() == 422) } } @Override public void onFailure(Call<Profile> call, Throwable t) { } }); 你的意思是什么?如果您使用XML configsapp.config并且web.config存储在配置文件中,那么您可以使用businessDate类来实现此目的。

system.Configuration.ConfigurationManager

编辑:根据您的评论,您可以通过注册类型来解决此问题

<AppSetting>
<add key="businessDate" value="22/12/1786">
</AppSetting>

DateTime newdt = DateTime.ParseExact(ConfigurationManager.AppSetting["businessDate"], "dd/MM/yyyy", CultureInfo.InvariantCulture);
new Calculator(newdt);