java 混淆 注入无意义代码,依赖注入和code混淆

In Mark Seemann's book Dependency Injection in .NET, he states that more people are using DI containers with AUTO-REGISTRATION support where the container can resolve instances of the required concrete types without almost any sort of prior configuration, and this goes well with the convention over configuration architecture approach. but this made me wonder if i used an obfuscator wouldn't this break the code base and cause the container to fail because the conventions have changed ?

解决方案

You can typically still use dependency injection, even if you ship your application assemblies in an obfuscated way. This will work, because you would typically use generic typing (such as Register()) or typeof arguments (such as Register(typeof(IService), typeof(Impl))) to register types. In other words, everything the compiler can check for you will still work (when the obfuscator works correctly).

What you should watch closely is everything the compiler can't check. Things as:

Override constructor arguments by specifying the name of the argument using a string literal.

Any convension over configuration approach where the convension is based on a name instead of type information, such as postfixing the name of constructor arguments with "AppSetting" or "ConnectionString", expecting the name of all types to register end with "Controller", expecting types to be in a particular namespace.

So you will have to watch these issues carefully. Don't forget to safeguard yourself by creating a verifiable configuration and in your case I would verify this configuration on application startup (or add a command line switch so that the application can do a self-check).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值